Jump to content

Printing array from database.


i73

Recommended Posts

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 :) 

Link to comment
https://forums.phpfreaks.com/topic/285847-printing-array-from-database/
Share on other sites

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.

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); 

 

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.