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 4373 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
MySQL?
--------------------------------------------------------------------------
while (list...
|
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? mysql.sock has full permissions (read/write/execute), so
it should be accessable by user baisley. If I am...
|
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 approcah it, or is there a better way to
custom layour your display data. It's my understanding you can...
|
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
OleDbDataAdapter1.Fill(DataSet11, "employees") in page_load sub.
| |
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 for every 5 min.should i create another database that just store data for 5min before. i already have...
|
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 reading and replying to this post.
Regards,
Abhijit
P.S. I'd like to time-out and redirect to login...
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |