473,320 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

display data from mysql array one row at a time

wadro21
12
Hello everyone,

i am trying to pull from a myql database all records from a table with multiple rows. i need to be able to call the data from each row one by one i would asume from an array. the trouble is i can select the data from mysql but dont know how to print the data in php one row at a time. here is my code:
Expand|Select|Wrap|Line Numbers
  1. $imgquery= "SELECT * FROM `forsale` where `row_id` != 1";
  2. $imginfo=mysql_query($imgquery);
  3.  
  4. while($get_img_info =mysql_fetch_array($imginfo, MYSQL_ASSOC)){
  5.  
  6.       $image=$get_img_info['pic_name'];
  7.  
  8. }
  9.         print $image;
there are 15 images in this array but i dont know how to call them.
Oct 24 '07 #1
6 4361
Markus
6,050 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. $imgquery= "SELECT * FROM `forsale` where `row_id` != 1";
  2. $imginfo=mysql_query($imgquery);
  3.  
  4. while($get_img_info =mysql_fetch_array($imginfo)){
  5.  
  6.      echo $get_img_info['pic_name']."<br />";
  7.  
  8. }
  9.  
  10.  
This will, or should, run through the images and print them out until the array returns false.

Sorry if i misunderstodd your question!
Oct 24 '07 #2
wadro21
12
close, but what i need to do from here is to assign all of the printed values into a new array that i can call one by one later on by number like array['1'], array['2'] or keep them in this array but to call them one by one.
Oct 24 '07 #3
Atli
5,058 Expert 4TB
Hi.

Using Markus' code you can do whatever you want with the value. You could simply change the echo statement so it adds it to an array instead.
Oct 24 '07 #4
Markus
6,050 Expert 4TB
I'm not sure how i would do that actually, i look forward to seeing an answer :)
Oct 24 '07 #5
wadro21
12
so what is the code that would put it into an array? i know what i need it to do, i'm just not sure how to do it.
Oct 25 '07 #6
Atli
5,058 Expert 4TB
Consider this alteration of Marcus' code.
Expand|Select|Wrap|Line Numbers
  1. # As you are only using the 'pic_name' field in you table I've
  2. # replaced the * with the field name to increase efficiency.
  3. $imgquery= "SELECT `pic_name` FROM `forsale` where `row_id` != 1";
  4. $imginfo=mysql_query($imgquery);
  5.  
  6. # This creates an empty array.
  7. $myArr = array();
  8.  
  9. # Note that I use the mysql_fetch_assoc() function here instead 
  10. # of the mysql_fetch_array() function to increase efficiency.
  11. while($get_img_info =mysql_fetch_assoc($imginfo))
  12. {
  13.     # This adds the 'pic_name' field of the current row to the
  14.     # next available index in the array, starting with 0.
  15.     $myArr[] = $get_img_info['pic_name'];
  16. }
  17.  
  18. # Now you can call fields using indexes like so
  19. $row0 = $myArr[0]
  20. $row1 = $myArr[1];
  21. # etc...
  22.  
  23. # Or you can loop through them all using a foreach loop
  24. foreach($myArr as $_k => $_v) 
  25. {
  26.   echo "Row {$_k}: {$_v} <br />";
  27. }
  28.  
Is this what you had in mind?
Oct 25 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Philip D Heady | last post by:
Ok, as some of you may know I'm an Oracle newbie w/ PHP. I'd rather use MySQL but at the office here we use Oracle and boy do I have alot to learn. I'm starting to hate it after using MySQL!! ...
2
by: Brett B | last post by:
I just installed mysql on linux. If I open a terminal, su to root, then type "mysql", I am able to connect to the server and run my queries. If I exit out of su so that I am my own id (baisley)...
0
by: Ben | last post by:
Hi, Can you display data, for example datagrid, in a "Formatted Excel Form" dynamically? I mean the data in datagrid will be display on the webpage as Full Formatted Excel like frame, different...
4
by: Rudy | last post by:
Hello all! I would like to take a row from a table and display this info in a nice layout. I tried the the reapeater, can't seemm to do too much with that. And I don't want a grid layout. I...
5
by: yma | last post by:
Hello, I tried to display a column in MS Access 2000 nwind.mdb using 3 data controls. But I got "It is already opened exclusively by another user, or you need permission to view its data." I...
4
by: seth_hickel | last post by:
With other solutions I would get a recordset, read each record and display data by formating my html as I wanted to display values of each record. I am trying to display data in a three column...
4
by: JuAn2226 | last post by:
Hi, can anyone help me . when my program starts there is numbers and time will be display in the form of visual basic. it will run continuesly .My problem here is i dont know how to display the data...
0
by: abhighat4214 | last post by:
Hello All, Actually I wanted to implement a MySQL connection time-out for the data-entry application which I developed in PHP. I just wanted to know is there any function in PHP-MYSQL lib that...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.