html - How to display specific value from database to a page using php? -


i'm new php , mysql , got stuck here. have database stores image paths. , these images displayed on page. now, have column called "upvotes" in database table , want display value "upvotes" database php page - under each image it's own value. i'd able increase or decrease "upvotes" value directly page , order images upvotes least upvotes.

here's code display images:

<?php     $query_image = "select * acc_images";     $result = mysql_query($query_image);     if(mysql_num_rows($result) > 0)     {         while($row = mysql_fetch_array($result))         {             echo '<img alt="" src="images/'.$row["image"].'"><br><br>';         }     }     else     {         echo 'file name not found in database';     } ?> 

to specify data returning database need refine mysql query.

$results = mysql_query("select 'columnname' `table` 'value' = '1'"); 

the * in mysql query mean select data.

you want

$query_image = "select 'upvotes' acc_images"; asuming upvotes column in acc_images table.

please note mysql functions deprecated , should using mysqli functions, http://uk1.php.net/mysqli

http://uk1.php.net/mysqli_query


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -