Prev and Next buttons - php

I'm new and still learning php&mysql. Search all day and tried different tutorials but nothing happen. So far I have only this with which I fetch text from my DB. How can I make prev and next buttons here?
if($q = mysqli_query($con, 'SELECT * FROM joke WHERE `id` = ' . mysqli_real_escape_string($con,$_GET['id']))){
if($row = mysqli_fetch_array($q)){
echo nl2br($row['text']);
echo '<div id="data">Date ' . $row['date'] . "</div>';
} else {
echo 'Not found';
}
} else {
echo mysqli_error($con);
}
echo "</div>";
$query = "select * from joke order by RAND() LIMIT 1";
$result = mysqli_query($con, $query) or die("Query failed: " . mysqli_errno($con));
while ($row = mysqli_fetch_array($result, MYSQL_BOTH)){
echo 'Random';
}

if i understand you correctly you want to display the next and previous joke based on id,
so you want to select max(id) from joke where id < the current id
and ... select min(id) from joke where id > the current id
$currentId = mysqli_real_escape_string($con,$_GET['id']);
if($q = mysqli_query($con, 'SELECT *,
(SELECT IFNULL(max(id),-1) FROM joke WHERE `id` < '.$currentId.') as previousid,
(SELECT IFNULL(min(id),-1) FROM joke WHERE `id` > '.$currentId.') as nextid
FROM joke WHERE `id` = ' . $currentId)){
if($row = mysqli_fetch_array($q, MYSQL_BOTH)){
echo nl2br($row['text']);
echo '<div id="data">Date ' . $row['date'] . '</div>';
if ($row['previousid'] > -1){
echo 'Previous';
}
if ($row['nextid'] > -1){
echo 'Next';
}
} else {
echo 'Not found';
}
} else {
echo mysqli_error($con);
}
echo "</div>";
$query = "select * from joke order by RAND() LIMIT 1";
$result = mysqli_query($con, $query) or die("Query failed: " . mysqli_errno($con));
while ($row = mysqli_fetch_array($result, MYSQL_BOTH)){
echo 'Random';
}

Related

Sorting SQL table using PHP

I am having problems with sorting a table using PHP. I just want to figure out how to make buttons from which I can sort a table by criteria without damaging the code. The criteria are to sort three columns "Price", "ArtistName" and "AlbumName" in ascending and descending order. I am looking forward to opinions and I will be thankful for any tips.
<?php
$con = mysqli_connect("", "", "", "");
if (!$con) {
die("Error: " . mysqli_connect_error());
}
$mysqlget = "SELECT * FROM Albums";
$mysqldata = mysqli_query($con, $mysqlget) or die ("Error: " . mysql_error($con));
echo "<table class='table_albums'>";
echo "<tr><th>Album</th><th>Description</th><th>Artist</th><th>Price</th><th colspan='2'>Additional Options</th></tr>";
while ($row = mysqli_fetch_array($mysqldata, MYSQLI_ASSOC)) {
echo "<tr><td>";
echo "<img class='album_artwork' src='";
echo $row['AlbumImage'];
echo "'></td><td><p class='info_album_artist'>";
echo $row['Info'];
echo "<p></td><td>";
echo "<img class='artist_artwork' src='";
echo $row['ArtistImage'];
echo "'></td><td><p class='info_album_artist'>£";
echo $row['Price'];
echo "<p></td><td>";
echo "<a href='";
echo $row['MoreInfo'];
echo "' class='more_info'>More Info</a></td><td>";
echo $row['Buy'];
echo "</td></tr>";
}
echo "</table>";
?>
There you go with all options
<form method="post" action="">
<select name="sort" onchange="this.form.submit()">
<option>Order by ...</option>
<option value="price_desc">Price descending</option>
<option value="price_asc">Price ascending</option>
<option value="artist_name_desc">Artist Name descending</option>
<option value="artist_name_asc">Artist Name ascending</option>
<option value="album_name_desc">Album Name descending</option>
<option value="album_name_asc">Album Name ascending</option>
</select>
</form>
<?php
$sort = $_POST['sort'];
if ($sort == 'price_desc')
{
$mysqlget = "SELECT * FROM Albums ORDER BY Price DESC";
}
else if ($sort == 'price_asc')
{
$mysqlget = "SELECT * FROM Albums ORDER BY Price ASC";
}
else if ($sort == 'artist_name_desc')
{
$mysqlget = "SELECT * FROM Albums ORDER BY ArtistName DESC";
}
else if ($sort == 'artist_name_asc')
{
$mysqlget = "SELECT * FROM Albums ORDER BY ArtistName ASC";
}
else if ($sort == 'album_name_desc')
{
$mysqlget = "SELECT * FROM Albums ORDER BY AlbumName DESC";
}
else if ($sort == 'album_name_asc')
{
$mysqlget = "SELECT * FROM Albums ORDER BY AlbumName ASC";
}
else
{
$mysqlget = "SELECT * FROM Albums";
}
$mysqldata = mysqli_query($con, $mysqlget) or die ("Error: " . mysql_error($con));
echo "<table class='table_albums'>";
echo "<tr><th>Album</th><th>Description</th><th>Artist</th><th>Price</th><th colspan='2'>Additional Options</th></tr>";
while ($row = mysqli_fetch_array($mysqldata, MYSQLI_ASSOC)) {
echo "<tr><td>";
echo "<img class='album_artwork' src='";
echo $row['AlbumImage'];
echo "'></td><td><p class='info_album_artist'>";
echo $row['Info'];
echo "<p></td><td>";
echo "<img class='artist_artwork' src='";
echo $row['ArtistImage'];
echo "'></td><td><p class='info_album_artist'>£";
echo $row['Price'];
echo "<p></td><td>";
echo "<a href='";
echo $row['MoreInfo'];
echo "' class='more_info'>More Info</a></td><td>";
echo $row['Buy'];
echo "</td></tr>";
}
echo "</table>";
?>
That's easy using SQL. Example:
Sort by Info:
SELECT * FROM Albums ORDER BY Info
Sort in descending order:
SELECT * FROM Albums ORDER BY Info DESC
To make buttons that sort the table, I would use GET, like:
Info
PHP code:
$mysqlget = 'SElECT * FROM Albums';
if (isset($_GET['orderby'])) {
switch ($_GET['orderby']) {
case 'Info':
$mysqlget .= ' ORDER BY Info';
break;
case 'Artist':
$mysqlget .= ' ORDER BY Artist';
break;
// ...
}
}
$mysqldata = mysqli_query($con, $mysqlget) or die ("Error: " . mysql_error($con));

Display row that is not repeated linking with database

I am new in php. I make a quiz app and I want to show questions that is not repeated again . here's my code.
Please help me to show require result.
<?php
include('connect.php');
$sql = "SELECT * FROM quiz_question WHERE theme_id= 2 ORDER BY RAND ()";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$id = $row['id'];
echo "
<h2>" . $row["question"]. "</h2>";
break;
}
}
$check_id = array ($row['id']);
echo $check_id['0'];
if(array ($row['id']) == $check_id){
echo "no question ";
}
else{
echo "
<h2>" . $row["question"]. "</h2>";
}
?>
Your question is not clear. But I guess, you can solve it by array_unique($array).
array_unique($array);
<?php
include('connect.php');
$sql = "SELECT * FROM quiz_question WHERE theme_id= 2 ORDER BY RAND ()";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$id = $row['id'];
$question = $row['question'];
echo "
<h2>" . $row["question"]. "</h2>";
$check_id = array($id);
}
}
$check_id_unique=array_unique($check_id);
?>

How can I show error message inside a form?

The page only show message when I click submit button, but now I want the message show inside the form after click submit button.How can I add some code or change the code following to make the message can run inside the form?
Here is my php code:
<?php
function topic_go($id){
echo "<meta http-equiv=\"refresh\" content=\"0;url=main_forum.php?act=topic&id=".$id."\">";
}
$id = $_GET['id'];
if(!$_SESSION['sign_in']){
$sql4= "SELECT * FROM categories WHERE level <".$_SESSION['userlevel']."+1";
$res4= mysql_query($sql4) or die (mysql_error());
$row4 = mysql_fetch_assoc($res4);
$sql5= "SELECT * FROM sub_categories WHERE sub_id ='".$id."'";
$res5 = mysql_query($sql5) or die (mysql_error());
$row5 = mysql_fetch_assoc($res5);
echo "<script type=\"text/javascript\">";
echo "alert('Please Login To Create Topic!');";
echo "window.location='main_forum.php?act=forum&id=".$row5['sub_id']."'";
echo "</script>";
}else{
if($id){
$sql="SELECT * FROM sub_categories WHERE sub_id = '".$id."'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 0){
echo "The forum you are trying to create a topic on, does not exist!\n";
}else{
$row1 = mysql_fetch_assoc($res);
if ($row1['level'] == 1 && $admin_user_level == 0){
echo "You are not an administrator, you cannot post on this forum";
}else {
if (!$_POST['submit']) {
echo "<table bgcolor=\"#CFFAE4\" cellspacing=\"10\" align=\"center\">\n";
echo "<form method=\"post\" action=\"./main_forum.php?act=create&id=".$id."\">\n";
echo "<tr><td>Forum Sub Category</td><td><select name=\"cat\" style=\"font-size:16px;\">\n";
$sql2= "SELECT * FROM categories WHERE level <".$admin_user_level."+1";
$res2= mysql_query($sql2) or die (mysql_error());
while($row = mysql_fetch_assoc($res2)){
$sql3= "SELECT * FROM sub_categories WHERE sub_cid = '".$row['cat_id']."'";
$res3 = mysql_query($sql3) or die (mysql_error());
echo "<option value=\"0\">".$row['cat_name']."</option>\n";
while($row2 = mysql_fetch_assoc($res3)){
$selected = ($row2['sub_id'] == $id) ? " SELECTED" : "";
echo "<option value=\"".$row2['sub_id']."\"".$selected."> ".$row2['sub_name']."</option>\n";
}
}
echo "</select></td></tr>\n";
echo "<tr><td valign=\"top\">Topic Title</td><td><textarea name=\"title\" style=\"width:400px;height:50px;font-size:16px\"></textarea></td></tr>\n";
echo "<tr><td valign=\"top\">Message</td><td><textarea name=\"message\" style=\"width:500px;height:300px;font-size:20px;\"></textarea></td></tr>\n";
echo "<tr><td colspan=\"2\" align=\"right\"><input type=\"button\" onClick=\"history.go(-1);\" value=\"Back\" class=\"btnz btnz_color\"> <input type=\"submit\" name=\"submit\" value=\"Create Topic\" class=\"btnz btnz_color\"></td></tr>\n";
echo "</form></table>\n";
}else{
$cat = $_POST['cat'];
$title = $_POST['title'];
$msg = $_POST['message'];
if($cat && $title && $msg){
$sql = "SELECT level FROM sub_categories WHERE sub_id ='".$cat."'";
$res = mysql_query($sql) or die (mysql_error());
if(mysql_num_rows($res)==0){
echo "This forum sub category does not exist!\n";
} else{
$row = mysql_fetch_assoc($res);
if ($row['level'] == 1 && $admin_user_level !=1){
echo "You are not an admin therefore you cannot post a new topic!";
}else{
if (strlen($title) < 3 || strlen($title) > 1000){
echo "The title must between 3 and 1000 characters!\n";
}else{
if(strlen($msg) < 3 || strlen($msg) > 10000){
echo "The message must between 3 and 10,000 characters!\n";
}else{
$date = date("m-d-y") . " at " . date("h:i:s");
$time = time();
$sql2 = "INSERT INTO topics (topic_cid, topic_title, topic_uid, topic_date, topic_time, topic_message)
VALUES('".$cat."','".$title."','".$_SESSION['userid']."','".$date."','".$time."','".$msg."')";
$res2 = mysql_query($sql2) or die (mysql_error());
$tid = mysql_insert_id();
topic_go($tid);
}
}
}
}
}else{
echo "Please supply all fields!\n";
} }} }
}
}?>
Thank You For Helping!

Single row repeating instead of displaying

I'm pretty new at PHP/MySQL, so please be patient with me.
I am trying to get a list of members in a table to show up on a page. Right now it's showing the first member about 10 times and not displaying anyone else's name. I DID have it working, but I don't know what happened. I just want it to display everyone's name once. Here is my code:
<?php $select = mysql_query("SELECT * FROM `member_staff` WHERE `username`='$_SESSION[USR_LOGIN]' AND `status`='Active'");
$row = mysql_fetch_array($select);
$rows = mysql_num_rows($select);
$teaching = $row[teaching];
if ($rows==0){echo "Sorry, you don't appear to be a professor.";}
else { ?>
<?php }
$select2 = mysql_query("SELECT * FROM `classes_enrolled` WHERE `course`='" . $teaching . "' ORDER BY `student_name`") or die(mysql_error());
$count = mysql_num_rows($select2);
$row2 = mysql_fetch_array($select2);
$student=$row2[student_name];
if($count==NULL) {
echo "<table width=\"80%\">\n";
echo "<tr><td><center>Nobody has registered for your class yet!</center></td></tr>\n";
echo "</table>\n";
echo "<br /><br />\n\n";
}
else {
echo "<center><font size=\"3\"><b>YEAR 1, TERM 2</b></font></center>";
echo "<table width=\"80%\" class=\"table-stripes\">\n";
echo "<tr><td width=\"50%\"><b>STUDENT</b></td></tr>\n";
$select3 = mysql_query("SELECT * FROM `members` WHERE `username`='" . $student . "'") or die(mysql_error());
$row3 = mysql_fetch_array($select3);
while($row2 = mysql_fetch_array($select2)) {
$house=$row3[house];
echo "<tr><td><strong class=\"$house\">$student</strong></td></tr>";
}
echo "</table>"; }
?>
I miss look on your code, since it is mess, but disregard the mysqli and mysql thing, you want to show how many student in the teacher's classes.
<?php $select = mysql_query("SELECT * FROM `member_staff` WHERE `username`='$_SESSION[USR_LOGIN]' AND `status`='Active'");
$row = mysql_fetch_array($select);
$rows = mysql_num_rows($select);
$teaching = $row[teaching]; <--- This only get first row of the course, if you want multiple course under same username, you need to loop it.
if ($rows==0){echo "Sorry, you don't appear to be a professor.";}
else { ?>
<?php }
$select2 = mysql_query("SELECT * FROM `classes_enrolled` WHERE `course`='" . $teaching . "' ORDER BY `student_name`") or die(mysql_error());
$count = mysql_num_rows($select2);
$row2 = mysql_fetch_array($select2);
$student=$row2[student_name]; <----- This only get the first row of the student name, if you want multiple student under a course, you need to loop it.
if($count==NULL) {
echo "<table width=\"80%\">\n";
echo "<tr><td><center>Nobody has registered for your class yet!</center></td></tr>\n";
echo "</table>\n";
echo "<br /><br />\n\n";
}
else {
echo "<center><font size=\"3\"><b>YEAR 1, TERM 2</b></font></center>";
echo "<table width=\"80%\" class=\"table-stripes\">\n";
echo "<tr><td width=\"50%\"><b>STUDENT</b></td></tr>\n";
$select3 = mysql_query("SELECT * FROM `members` WHERE `username`='" . $student . "'") or die(mysql_error());
$row3 = mysql_fetch_array($select3);
while($row2 = mysql_fetch_array($select2)) {
$house=$row3[house]; <----This only show the first row of $house under same student, so you need to loop it too.
echo "<tr><td><strong class=\"$house\">$student</strong></td></tr>";
}
echo "</table>"; }
?>
So what you really want to do is
<?php
$select = mysql_query("SELECT * FROM `member_staff` WHERE `username`='$_SESSION[USR_LOGIN]' AND `status`='Active'");
$rows = mysql_num_rows($select);
if ($rows==0){echo "Sorry, you don't appear to be a professor.";}
else { ?>
<?php }
while( $row = mysqli_fetch_array( $select ) ) {
$teaching = $row[teaching];
$select2 = mysql_query("SELECT * FROM `classes_enrolled` WHERE `course`='" . $teaching . "' ORDER BY `student_name`") or die(mysql_error());
$count = mysql_num_rows($select2);
if($count==NULL) {
echo "<table width=\"80%\">\n";
echo "<tr><td><center>Nobody has registered for your class yet!</center></td></tr>\n";
echo "</table>\n";
echo "<br /><br />\n\n";
} else {
while( $row2 = mysql_fetch_array($select2) ) {
$student=$row2[student_name];
echo "<center><font size=\"3\"><b>YEAR 1, TERM 2</b></font></center>";
echo "<table width=\"80%\" class=\"table-stripes\">\n";
echo "<tr><td width=\"50%\"><b>STUDENT</b></td></tr>\n";
$select3 = mysql_query("SELECT * FROM `members` WHERE `username`='" . $student . "'") or die(mysql_error());
while($row3 = mysql_fetch_array($select3)) {
$house=$row3[house];
echo "<tr><td><strong class=\"$house\">$student</strong></td></tr>";
}
echo "</table>";
}
} // END ELSE
}
} // END ELSE
?>

Catgories didn't work

So I try to learn php and decided to make one site where I add images, save them in folder and id, name,type, path in mysql. Then show on page. So far I have upload form and I can upload and save images. Also I showing them successfully on the page.
Now I'm trying to make categories like - Nature, Funny ... etc. So I added one field in my main table -> img_category.
Also I madded second table - cats whit cat_id and cat_name fields. Using this to show the categories on the page:
<?php
$q = mysqli_query($con,"select * from cats");
while ($res = mysqli_fetch_assoc($q))
{
echo '<a href="pic.php?cat_id='. $res['cat_id'] .'">'.$res['cat_name'].'<br/>';
}
So now how can I make when I click on some category link to load images only from this category?
I have managed to make something like this but it doesn't work like is expected
<?php
$q = mysqli_query($con,"select * from cats");
while ($res = mysqli_fetch_assoc($q))
{
echo '<a href="pic.php?cat_id='. $res['cat_id'] .'">'.$res['cat_name'].'<br/>';
}
?>
<hr>
<?php
$cat_id = $_GET['cat_id'];
$query = "SELECT * FROM images JOIN cats ON images.img_category = cats.cat_id WHERE cats.cat_id = '$cat_id'";
$result = mysqli_query($con, $query) or die("Query failed: " . mysqli_errno($con));
$line = mysqli_fetch_array($result, MYSQL_BOTH);
if (!$line) echo '';
$previd = -1;
$currid = $line[0];
if (isset($_GET['id'])) {
do {
$currid = $line[0];
if ($currid == $_GET['id']) break;
$previd = $currid;
$line = mysqli_fetch_array($result, MYSQL_BOTH);
} while ($line);
}
if ($line) {
echo "<div id=\"picture\">";
echo "<img style=\"width:100%;margin:0 auto;\" src=\"upload/".$line['name']."\" /></a><br />";
echo "<div id=\"caption\">".$line['caption']."</div><br />";
}
else echo "There is no images!\n";
if ($previd > -1) echo '<span>Prev</span>';
echo str_repeat(' ', 5);
$line = mysqli_fetch_array($result, MYSQL_BOTH);
$query = "select * from images order by RAND() LIMIT 1";
$result = mysqli_query($con, $query) or die("Query failed: " . mysqli_errno($con));
while ($row = mysqli_fetch_array($result, MYSQL_BOTH)){
echo 'Random';
}
echo str_repeat(' ', 5);
if ($line) echo '<span>Next</span> <br /><br />';
echo "</div>";
?>
The results are:
When there is image in the category is showed but and if I click on 'Next' button I get the same image.
If there is no image in the category I get all echoes like link whit the ID of last category for exam: There is no image like link and if I click it I get last category ID loaded. In my case I have 8 categories so ID=8.
Any help is appreciate!
Thank's
EDIT:
Ok this line:
echo '<span>Следваща</span>
Where is pic.php?cat_id=... i think is wrong. Here I must take next image ID not next category ID. But how to change it for image? If i make it pic.php?id=... I get empty page.
I don't understand it. I know that is messy code but is best I can do for now.
EDIT 2:
I've made something like this. Now can you help me how to make query's for next image because now didn't get next image and stay the same.
$cat_id = $_GET['cat_id'];
$cat_id = mysqli_real_escape_string($con, $cat_id);
$query = "SELECT * FROM images JOIN cats ON images.img_category = cats.cat_id WHERE cats.cat_id = '$cat_id'";
$result = mysqli_query($con, $query) or die("Query failed: " . mysqli_errno($con));
$prevSQL = mysqli_query($con,"SELECT cat_id FROM cats WHERE cat_id < $cat_id ORDER BY cat_id DESC LIMIT 1") or die (mysqli_error($con));
$nextSQL = mysqli_query($con, "SELECT cat_id FROM cats WHERE cat_id > $cat_id ORDER BY cat_id ASC LIMIT 1") or die (mysqli_error($con));
$prevobj=mysqli_fetch_object($prevSQL);
$nextobj=mysqli_fetch_object($nextSQL);
$pc = mysqli_fetch_object(mysqli_query($con, "SELECT COUNT(cat_id) as pid FROM cats WHERE cat_id<$cat_id ORDER BY cat_id DESC")) or die (mysqli_error($con));
$nc = mysqli_fetch_object(mysqli_query($con, "SELECT COUNT(cat_id) as nid FROM cats WHERE cat_id>$cat_id ORDER BY cat_id ASC")) or die (mysqli_error($con));
$prev=$pc->pid>0 ? 'Prev |' : '';
$next=$nc->nid>0 ? 'Next' : '';
$row = mysqli_fetch_array($result);
echo "<div id=\"picture\">";
echo "<img src=\"upload/" . $row['name'] . "\" alt=\"\" /><br />";
echo $row['caption'] . "<br />";
echo "</p>";
echo $prev;
echo $next;
As you stated, I guess the error is with the line:
echo '<span>Следваща</span>
I think it should be:
echo '<span>Следваща</span>
EDIT:
Your code should look like:
<?php
$q = mysqli_query($con,"select * from cats");
while ($res = mysqli_fetch_assoc($q))
{
echo '<a href="pic.php?cat_id='. $res['cat_id'] .'">'.$res['cat_name'].'<br/>';
}
?>
<hr>
<?php
$cat_id = $_GET['cat_id'];
$query = "SELECT * FROM images JOIN cats ON images.img_category = cats.cat_id WHERE cats.cat_id = '$cat_id'";
$result = mysqli_query($con, $query) or die("Query failed: " . mysqli_errno($con));
$line = mysqli_fetch_array($result, MYSQL_BOTH);
if (!$line) echo '';
$previd = -1;
$currid = $line[0];
if (isset($_GET['id'])) {
do {
$currid = $line[0];
if ($currid == $_GET['id']) break;
$previd = $currid;
$line = mysqli_fetch_array($result, MYSQL_BOTH);
} while ($line);
}
if ($line) {
echo "<div id=\"picture\">";
echo "<img style=\"width:100%;margin:0 auto;\" src=\"upload/".$line['name']."\" /></a><br />";
echo "<div id=\"caption\">".$line['caption']."</div><br />";
}
else echo "There is no images!\n";
if ($previd > -1) echo '<span>Prev</span>';
echo str_repeat(' ', 5);
$line = mysqli_fetch_array($result, MYSQL_BOTH);
$query = "select * from images order by RAND() LIMIT 1";
$result = mysqli_query($con, $query) or die("Query failed: " . mysqli_errno($con));
while ($row = mysqli_fetch_array($result, MYSQL_BOTH)){
echo 'Random';
}
echo str_repeat(' ', 5);
if ($line) echo '<span>Next</span> <br /><br />';
echo "</div>";
?>
Try this
<?php
if(isset($_GET['cat_id'])){
$cat_id = $_GET['cat_id'];
$query = "SELECT * FROM images WHERE img_category = '$cat_id'";
$result = mysqli_query($con, $query) or die("Query failed: " . mysqli_errno($con));
$line = mysqli_fetch_array($result, MYSQL_BOTH);
if (!$line) echo '';
$previd = -1;
$currid = $line[0];
if (isset($_GET['id'])) {
$previous_ids = array();
do {
$previous_ids[] = $line[0];
$currid = $line[0];
if ($currid == $_GET['id']) break;
$previd = end($previous_ids);
$line = mysqli_fetch_array($result, MYSQL_BOTH);
} while ($line);
}
if ($line) {
echo "<div id=\"picture\">";
echo "<img style=\"width:100%;margin:0 auto;\" src=\"upload/".$line['name']."\" /><br />\r";
echo "<div id=\"caption\">".$line['caption']."</div><br />";
}
else echo "There is no images!\n";
if ($previd > -1)
echo '<span>Prev</span>';
echo str_repeat(' ', 5);
$line = mysqli_fetch_array($result, MYSQL_BOTH);
$query = "select * from images WHERE img_category = '$cat_id' order by RAND() LIMIT 1";
$result = mysqli_query($con, $query) or die("Query failed: " . mysqli_errno($con));
while ($row = mysqli_fetch_array($result, MYSQL_BOTH)){
echo 'Random';
}
echo str_repeat(' ', 5);
if ($line) echo '<span>Next</span> <br /><br />';
echo "</div>\r";
}
?>

Categories