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: -
$imgquery= "SELECT * FROM `forsale` where `row_id` != 1";
-
$imginfo=mysql_query($imgquery);
-
-
while($get_img_info =mysql_fetch_array($imginfo, MYSQL_ASSOC)){
-
-
$image=$get_img_info['pic_name'];
-
-
}
-
print $image;
there are 15 images in this array but i dont know how to call them.
6 4366 Markus 6,050
Recognized Expert Expert -
$imgquery= "SELECT * FROM `forsale` where `row_id` != 1";
-
$imginfo=mysql_query($imgquery);
-
-
while($get_img_info =mysql_fetch_array($imginfo)){
-
-
echo $get_img_info['pic_name']."<br />";
-
-
}
-
-
This will, or should, run through the images and print them out until the array returns false.
Sorry if i misunderstodd your question!
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.
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.
Markus 6,050
Recognized Expert Expert
I'm not sure how i would do that actually, i look forward to seeing an answer :)
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.
Atli 5,058
Recognized Expert Expert
Consider this alteration of Marcus' code. -
# As you are only using the 'pic_name' field in you table I've
-
# replaced the * with the field name to increase efficiency.
-
$imgquery= "SELECT `pic_name` FROM `forsale` where `row_id` != 1";
-
$imginfo=mysql_query($imgquery);
-
-
# This creates an empty array.
-
$myArr = array();
-
-
# Note that I use the mysql_fetch_assoc() function here instead
-
# of the mysql_fetch_array() function to increase efficiency.
-
while($get_img_info =mysql_fetch_assoc($imginfo))
-
{
-
# This adds the 'pic_name' field of the current row to the
-
# next available index in the array, starting with 0.
-
$myArr[] = $get_img_info['pic_name'];
-
}
-
-
# Now you can call fields using indexes like so
-
$row0 = $myArr[0]
-
$row1 = $myArr[1];
-
# etc...
-
-
# Or you can loop through them all using a foreach loop
-
foreach($myArr as $_k => $_v)
-
{
-
echo "Row {$_k}: {$_v} <br />";
-
}
-
Is this what you had in mind?
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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?...
|
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,
|
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...
|
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...
| |
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.
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |