473,545 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

display data from mysql array one row at a time

wadro21
12 New Member
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 4366
Markus
6,050 Recognized Expert Expert
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 New Member
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 Recognized Expert Expert
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 Recognized Expert Expert
I'm not sure how i would do that actually, i look forward to seeing an answer :)
Oct 24 '07 #5
wadro21
12 New Member
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 Recognized Expert Expert
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
7033
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!! -------------------------------------------------------------------------- 1) Is there a similar statement using PHP/Oracle functions as below for...
2
2892
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) and type "mysql", I get this error: Can't connect to local MySQL server through socket '/home/data/mysql/mysql.sock' (13) Any idea why?...
0
1768
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 font styles, formatted column header, colors... Please show me how or any information related. Thank you,
4
2129
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 would like to lay out a bunch of lable controls, and have each value from each row(one at a time) bind in. I just wonder if this is a good way to...
5
2175
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 put ole DataAdapter, Connection and dataset controls and fill in the properties of the listbox. The only code I have is...
4
2059
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 three row table with paging. How does this translate to ASP.NET - or - what ASP.NET tools do I use to accomplish this and how. Thank you.
4
1782
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 5min and before. Besides that i want to store this display for every 5 min and before. i already have database to store the number and time but not...
0
1406
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 takes care of the same ? Or Do I have to simulate that behaviour using some more lines of code ? Please guide me regarding the same. Thank You for...
0
7486
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7416
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7442
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7776
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6001
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4965
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
729
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.