Hey every one the question is simple but it is not working.
I have a query and i need to echo all the rows in this order :
First row echoed : Have the biggest ID
Last row echoed : Have the Smallest ID
Here is the code :
[code=php]
<div class = “chat” style = “padding : 1em;” >
<form action = “index.php” method = “POST” >
<input type = “text” name = “chat” style = “width:50%; height: 30px;” onkeypress=”return isNumberKey(event)” maxlength=”130″ >
<input type = “submit” name = “csub” value = “Share” >
</form>
</div>
<?php
if (empty($_POST[‘chat’])) {
echo ‘Share what is on your mind !’;
}else{
if (isset($_POST[‘csub’])) {
$chat = $_POST[‘chat’];
$date = date(“F j, Y, g:i a”);
require ‘connect.php’;
$userc = $_COOKIE[“user”];
mysqli_query($GLOBALS[“___mysqli_ston”], “INSERT INTO chat VALUES (‘NULL’, ‘$userc’, ‘$chat’, ‘$date’) “);
header(“Location: index.php”);
mysqli_close();
}
}
$servername = “localhost”;
$dbusername = “root”;
$password = “”;
$dbname = “a_database”;
$conn = new mysqli($servername, $dbusername, $password, $dbname);
if ($conn->connect_error) {
die(“Connection failed: ” . $conn->connect_error);
}
$sql = ”
SELECT * FROM chat
WHERE Username = ‘$userc’
OR Username IN(SELECT User_two FROM friends WHERE User_one = ‘$userc’)
OR Username IN(SELECT User_one FROM friends WHERE User_two = ‘$userc’)
“;
$result = $conn->query($sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo ‘
<div style = “padding : 1em; border :6px double gray; margin-top: 15px; background-color: white;” >
<table style = “width: 90%”>
<tr>
<td><b>’.$row[“Username”].'</b></td>
<td> ~ ‘.$row[“date”].'</td>
</tr>
<tr>
<td><IMG src=”http://www.mathblogging.org/images/icons/small-default-avatar.jpg”></td>
<td>’.$row[“chat”].'</td>
</tr>
</table>
</div>’;
}
}
?>
Please i have been looking for days and no answer. Thanks for reading.
All i want is to tell me how to edit the code because i tried using all the PHP functions i could find :
Last_Inserted_Id
Order by …
ANd none work they always give me errors. (expected mysqli Boolean given)