bahaa
Members-
Posts
147 -
Joined
-
Last visited
Everything posted by bahaa
-
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 ?
-
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; }
-
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.
-
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; }
-
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-
-
How To Get Online User And Online Guest ?
bahaa replied to bahaa's topic in MySQL: Visual QuickStart Guide (2nd Edition)
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. -
How To Get Online User And Online Guest ?
bahaa replied to bahaa's topic in MySQL: Visual QuickStart Guide (2nd Edition)
I am using MySQL database and here is the session table -
How To Get Online User And Online Guest ?
bahaa replied to bahaa's topic in MySQL: Visual QuickStart Guide (2nd Edition)
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. -
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
-
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?