Jump to content

Printing array from database.


Go to solution Solved by Barand,

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

  • Solution

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

Edited by i73

 

 

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.