i73 Posted February 1, 2014 Share Posted February 1, 2014 Hey guys, I have some images and videos that I want to print out from the database from the, most views, most comments etc where the top values would be at the top of the array when output. I have never fully grasped arrays while learning, just trying to figure out how to do this. $video_array=array($video_info3['video_id']); foreach($video_array as $x=>$x_value) { echo $x . ", Value=" . $x_value; echo "<br>"; } I was thinking something like that... But it wont output from the database. Also is this the best way to call values from the database? $video_info="SELECT * from video where video_id=$video_id"; $video_info2=mysql_query($video_info) or die("could not select video directory"); $video_info3=mysql_fetch_array($video_info2); $video_info3['variables']; Thanks in advance, I hope you can help Quote Link to comment https://forums.phpfreaks.com/topic/285847-printing-array-from-database/ Share on other sites More sharing options...
Solution Barand Posted February 1, 2014 Solution Share Posted February 1, 2014 Don't use "SELECT * ", specify just the columns you need. Use mysql_fetch_assoc() instead of mysql_fetch_array(). $video_info3 will contain an array of the columns in the row. You can view its contents with echo '<pre>', print_r($video_info3, true), '</pre>'; Seeing what is in there should help you process the contents. You should stop using mysql and change to mysqli ASAP as the mysql functions will soon be no longer available. Quote Link to comment https://forums.phpfreaks.com/topic/285847-printing-array-from-database/#findComment-1467328 Share on other sites More sharing options...
i73 Posted February 1, 2014 Author Share Posted February 1, 2014 (edited) Don't use "SELECT * ", specify just the columns you need. Use mysql_fetch_assoc() instead of mysql_fetch_array(). $video_info3 will contain an array of the columns in the row. You can view its contents with echo '<pre>', print_r($video_info3, true), '</pre>'; Seeing what is in there should help you process the contents. You should stop using mysql and change to mysqli ASAP as the mysql functions will soon be no longer available. So? $video_info="SELECT `video_name` FROM `video`"; $video_info2=mysql_query(video_info) or die("could not select video directory"); $video_info3=mysql_fetch_array($video_info2); $video_name2=$video_info3['video_name']; would be best? and to be even more annoying, how would I do that in mysqli? would this be better than the above code? Also thanks for your help! $sql = "SELECT `user_name` FROM `user`"; $result = mysql_query($sql); Edited February 1, 2014 by i73 Quote Link to comment https://forums.phpfreaks.com/topic/285847-printing-array-from-database/#findComment-1467390 Share on other sites More sharing options...
Barand Posted February 2, 2014 Share Posted February 2, 2014 how would I do that in mysqli? http://uk1.php.net/manual/en/mysqli.query.php http://uk1.php.net/manual/en/mysqli-result.fetch-assoc.php would this be better than the above code? Also thanks for your help! $sql = "SELECT `user_name` FROM `user`"; $result = mysql_query($sql); iit certainly would if you wanted user_name rather than video_name Quote Link to comment https://forums.phpfreaks.com/topic/285847-printing-array-from-database/#findComment-1467394 Share on other sites More sharing options...
i73 Posted February 2, 2014 Author Share Posted February 2, 2014 http://uk1.php.net/manual/en/mysqli.query.php http://uk1.php.net/manual/en/mysqli-result.fetch-assoc.php iit certainly would if you wanted user_name rather than video_name Oh yeah, lol user_name is going to change to video_name Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/285847-printing-array-from-database/#findComment-1467395 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.