Jump to content
Larry Ullman's Book Forums

bahaa

Members
  • Posts

    147
  • Joined

  • Last visited

Everything posted by bahaa

  1. I know how to do the query but my problem is with this $stmt->bind_param(); the number of variable and data type to bind it to the code above depend on the user, so I am not sure how many variable will be used. How do I do it?
  2. My sql query would be like this $sql ="SELECT CategoryID, category.Title, Visible, Ordering, category_position.Title, CreationDate, CreatedBy, LastEdited, LastEditedBy FROM category LEFT JOIN category_position USING(PositionID) LEFT JOIN country_category USING(CategoryID)"; if($Visible ==1 OR $Visible ==1) { $sql .=" WHERE Visible = ? "; } $sql .=" ORDER BY Ordering "; How do I do the binding if they user did not choose to sort the outpout ?
  3. Thanks Larry I have another question. I have a page that display data from the database and I want to make sorting options by visibility and country. How do I bind an optional parameter to the prepared statement ? I know how to constrcut the the sql query but my problem is with the binding. Here is my statement function GetCategories() { global $mysqli; $sql ="SELECT CategoryID, category.Title, Visible, Ordering, category_position.Title, CreationDate, CreatedBy, LastEdited, LastEditedBy FROM category LEFT JOIN category_position USING(PositionID) LEFT JOIN country_category USING(CategoryID) ORDER BY Ordering "; //prepare the stmt $stmt = $mysqli->prepare($sql); //execute the stmt $stmt->execute(); //Store the result $stmt->store_result(); //Bind the result to variables $stmt->bind_result($CategoryID, $Title, $Visible, $Ordering, $Position, $CreationDate, $CreatedBy, $LastEdited, $LastEditedBy); //Get numRows if($stmt->num_rows >0 ) { //Fetch the array while($stmt->fetch()) {?> <tr> <td><input type="checkbox" name="chkCategoryID[]" class="chk" value="<?php echo $CategoryID; ?>"/></td> <td><?php echo $Title ;?></td> <td><?php echo $Position ; ?></td> <td> <?php if($Visible ==1) { echo '<img src="../images/icon-16-published.gif" width="16" height="16" alt="منشور" />'; } else { echo '<img src="../images/icon-16-unPublished.gif" width="16" height="16" alt="منشور" />'; } ?> </td> <td><input type="text" name="txtOrdering" value="<?php echo $Ordering; ?>"/></td> <td><?php echo $CreationDate; ?></td> <td><?php echo $LastEdited; ?></td> <td><?php echo GetUserByID($CreatedBy); ?></td> <td><?php echo GetUserByID($LastEditedBy); ?></td> </tr> <?php } } //Close connection $stmt->close(); //return the result return $stmt; }
  4. The transactions are used if you want to inster multi record to the database and you want to make sure all queries succeed or roll back if something went wrong. example of using transation is when transfering money from one account to another, if you send money to another acount and the money withdrown from you account and then something happens before the are deposited in the other account then everything roll back. So in the bank account example when useing the transation is forcing to the queries to roll back if something goes wrong.
  5. My function works, but what I want the fetching to happen out of the function not inside. In the one above the fetching is happening inside the function and I call it on my page to dispay the drop down.
  6. I check for the ID like this if(isset($_SESSION['UserID'])){ $UserID = (int)$_SESSION['UserID']}
  7. $sdbc is my connection. The function is not missing any thing, I posted 2 functions, the one without id is used when sign in up for new user and in this case there is no id to check for. the function that takes ID as a parameter is used when for updating.
  8. Here is 2 functions to check for unique email address, one used for insert and the other for update when you try to update a record and want to check for unique email, you have to check for all records except the one you are trying to use function uniqueEamilUpdate($email, $ID){ global $sdbc; $query = "SELECT userEmail, userID FROM user WHERE userEmail ='". mysqli_real_escape_string($sdbc, $email)."' AND userID !='". mysqli_real_escape_string($sdbc, $ID)."'"; $result = mysqli_query($sdbc, $query); return $result; } and here is a function to check for unique email on insert function uniqueEamil($email){ global $sdbc; $query = "SELECT userEmail, userID FROM user WHERE userEmail ='". mysqli_real_escape_string($sdbc, $email)."'"; $result = mysqli_query($sdbc, $query); return $result; }
  9. You don't need to use it anymore for alternat background color and you can use css instead you can use this selector tr:nth-child(odd) here is an example where I use it #container #content-box .content-elements .tblListData tbody tr:nth-child(odd){ background: #fff; border-top: 10px solid #FFF; }
  10. Hello, I recently started using the mysqli prepared statement and I am not so good with them yet. I have a mysqli prepared statement inside a function and it works fine but my problem is that I don't know how to fetch a mysqli prepared statement out side the function. here is my function function GetCountriesList() { global $mysqli; //Build sql query $sql ="SELECT CountryID, Name FROM country"; //Prepare the stmt $stmt = $mysqli->prepare($sql); //execute the stmt $stmt->execute(); //store the result $stmt->store_result(); //bind the result $stmt->bind_result($CountryID, $Country); $select= "<select name=\"cboCountry\">"; $select .="<option value=\"0\">الدولة</option>"; //fetch the result while($stmt->fetch() ) { $select .= "<option value=\"{$CountryID}\">{$Country}</option>"; } $select .="</select>"; return $select; } How do I fetch the result out side the function ? PHP/5.3.4 MySQL client version: mysqlnd 5.0.7-
  11. What is the problem with the constraints? Using the sql statement you provided, how would I get the online registered users and online guests? what should I do if I only want to get the online loggedin user in backened? What If I want to get the name of the onlined logged in users? If I want to know more about the strucuter of the whole database I would send it to you in private message.
  12. Can you give in an example if you got the time? I want to be able to get the online guest and onlined logged in users.
  13. Hi all, I have used the tutorial to store session in the database, but I am not quite sure how to use it to insert user id and also get online users and online gues. In the book you show how to delete the session when some one log out. How to we delete the session when the user close the browser without login out? Thanks in advance
  14. Yes, it is the time problem. I set the time to a different time zone that the server uses. I get my data insert with the date and time I want, but when I use now() in my query to select rows with them time I want, it uses the server time. How do I fix this?
  15. How do we get the length of a string without the spaces? I want to count only the words without the spaces.
  16. I know it is in the manual but the odd thing that it doesn't include today's post for some reason. for example: if I have post with these dates 2011-11-22, 2011-11-24, 2011-11-19, 2011-11-18 It only select 2011-11-19, 2011-11-18 but not 2011-11-22
  17. But WHERE articalPublishDate >= NOW() will select future date? If I set an artical to be published in 2011-12-23 and use WHERE articalPublishDate >= NOW() then the artical will be published before 2011-12-23 comes
  18. Hi all, I have a table with these fields :articalID, articalTitle, articalBody, articalPhoto, articalTags, articalPublishDate, articalView, articalVisible, userID, catID The articalPublishDate is a datetime type. FROM the CMS I set the date and times when the artical to be released or published. How do compare the articalPublishDate with the date and time now and select the row if date and time now equal or greater than the date and time in the table?
  19. Hello, How do we avoid cutting the last word when using the Left Or Right function in MYSQL to select a number x of characters from the database? If it is not possible with the mysql, is there any way to do it in PHP ? Bahaa,
  20. If I was working on this project, I would use the auto increment, but we are taking this in school and the teacher meant to not auto increment the ID field for teaching purposes , so she can show us how to use the sub query.
×
×
  • Create New...