Hi,
I need to store database data in variables so I can work with it.
Please se below what I am trying to do in my script....
If you echo the stuff out is work fine. Meaning if I go echo $row['a5]; I get the data I want but I can't get the data to store in a vairable.
I need something that goes from $a1 to $a18 and in each of then store the data from one field in the database name a5.
Thanks
[PHP]
<?php
$con = mysql_connect("localhost","*****","******");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("*******", $con);
$result = mysql_query("SELECT * FROM hole ORDER BY a5");
while($row = mysql_fetch_array($result))
{
$a1 = $row['a5'];
$a2 = $row['a5']; /////// needs to give second result
$a3 = $row['a5']; /////// needs to give third result
}
echo "<img name=\"Hole\" src=\"$a1.jpg\" width=\"32\" height=\"32\" alt=\"Hole\">";
mysql_close($con);
?>
[/PHP]
16 1970
Please remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).
This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions.
MODERATOR
Markus 6,050
Recognized Expert Expert
Hi,
I need to store database data in variables so I can work with it.
Please se below what I am trying to do in my script....
If you echo the stuff out is work fine. Meaning if I go echo $row['a5]; I get the data I want but I can't get the data to store in a vairable.
I need something that goes from $a1 to $a18 and in each of then store the data from one field in the database name a5.
Thanks
[PHP]
<?php
$con = mysql_connect("localhost","*****","******");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("*******", $con);
$result = mysql_query("SELECT * FROM hole ORDER BY a5");
while($row = mysql_fetch_array($result))
{
$a1 = $row['a5'];
$a2 = $row['a5']; /////// needs to give second result
$a3 = $row['a5']; /////// needs to give third result
}
echo "<img name=\"Hole\" src=\"$a1.jpg\" width=\"32\" height=\"32\" alt=\"Hole\">";
mysql_close($con);
?>
[/PHP]
This is untested (just some logic)
[php]
$_i = 0;
$_a = array();
while($_row = mysql_fetch_array($_res))
{
$_a[$_i] = $_row['col'];
++$_i;
}
[/php]
Your question is so not clear!
Do you want
1. to assign the content of column 'a5' in each subsequent row into a variable $a1
2. store the contents of column 'a5' of each row into 18 different variables starting with $a1-$a18?
3. store the content of column 'a5' in variables $a1-$a18, e.g. column 'a5' content from row 1 goes into $a1, from row 10 goes into $a10, from row 18 goes into $a18.
Please describe your problem a bit more clearer.
Ronald
Your question is so not clear!
Do you want
1. to assign the content of column 'a5' in each subsequent row into a variable $a1
2. store the contents of column 'a5' of each row into 18 different variables starting with $a1-$a18?
3. store the content of column 'a5' in variables $a1-$a18, e.g. column 'a5' content from row 1 goes into $a1, from row 10 goes into $a10, from row 18 goes into $a18.
Please describe your problem a bit more clearer.
Ronald
Hi yes.
Number 3.
3. store the content of column 'a5' in variables $a1-$a18, e.g. column 'a5' content from row 1 goes into $a1, from row 10 goes into $a10, from row 18 goes into $a18.
Please describe your problem a bit more clearer.
Markus 6,050
Recognized Expert Expert
Hi yes.
Number 3.
3. store the content of column 'a5' in variables $a1-$a18, e.g. column 'a5' content from row 1 goes into $a1, from row 10 goes into $a10, from row 18 goes into $a18.
Please describe your problem a bit more clearer.
Then my post should suffice.
I am testing it but for some reason it does not want to go...
Markus 6,050
Recognized Expert Expert
I am testing it but for some reason it does not want to go...
Post what youre using
[PHP]
<?php
$con = mysql_connect("l*****","*****","*****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("****datebase*****", $con);
$result = mysql_query("SELECT * FROM hole ORDER BY a5");
$i = 0;
$a = array();
while($row = mysql_fetch_array($result))
{
$a[$i] = $row['a5'];
++$i;
}
mysql_close($con);
////Testing
echo "$a1 $a2 $a3 ";
?>
[/PHP]
Markus 6,050
Recognized Expert Expert
[PHP]
<?php
$con = mysql_connect("l*****","*****","*****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("****datebase*****", $con);
$result = mysql_query("SELECT * FROM hole ORDER BY a5");
$i = 0;
$a = array();
while($row = mysql_fetch_array($result))
{
$a[$i] = $row['a5'];
++$i;
}
mysql_close($con);
////Testing
echo "$a1 $a2 $a3 ";
?>
[/PHP]
Remember, the variables are being assigned into an array - not seperate variables.
[php]
echo "{$_a[0]} {$_a[1]} {$_a[2]}";
[/php]
Super, it is working.!!!!!!!!!!!!!!
Never worked with it before but now i'll know!
Thanks a mil again!
Remember, the variables are being assigned into an array - not seperate variables.
[php]
echo "{$_a[0]} {$_a[1]} {$_a[2]}";
[/php]
That is cheating: the requirement was to assign them to separate variables $a1 - $a18. You can do that as follows:
[php]while($row = mysql_fetch_array($result))
{
$var='a'.$i;
$$var = $row['a5'];
++$i;
}
mysql_close($con);
////Testing
echo "$a1 $a2 $a3 ";[/php]Ronald
Markus 6,050
Recognized Expert Expert
Super, it is working.!!!!!!!!!!!!!!
Never worked with it before but now i'll know!
Thanks a mil again!
Welcome!
Regards.
:)
That is cheating: the requirement was to assign them to separate variables $a1 - $a18. You can do that as follows:
[php]while($row = mysql_fetch_array($result))
{
$var='a'.$i;
$$var = $row['a5'];
++$i;
}
mysql_close($con);
////Testing
echo "$a1 $a2 $a3 ";[/php]Ronald
This one work the best for me because I need to use the Vairables all over the place. Thanks!!!!!
As Markus already said: you are welcome!. See ya again.
Ronald
Markus 6,050
Recognized Expert Expert
As Markus already said: you are welcome!. See ya again.
Ronald
Thanks for that ron!
I knew there was a way to name vars but didn't know how.
:D
We can learn something each day from each other.
Ronald
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Corey Lubin |
last post by:
someGlobal=1
class Original:
def foo(self):
# Make use of someGlobal
from original import *
someGlobal=2
|
by: Terry |
last post by:
I have a number of input boxes used to display totals based on
selected items for each row in a table. There are more than a few
rows that are identical, except for the form field name. I have...
|
by: Eric |
last post by:
How can I dynamically assign an event to an element?
I have tried :
(myelement is a text input)
document.getElementById('myelement').onKeyUp =
"myfnc(param1,param2,param3)";
...
|
by: Shelby |
last post by:
Hi,
if I have :
rs.Fields("firstname").Value = "John"
rs.Fields("middlename").Value = "D"
rs.Fields("lastname").Value = "Paul"
Is it possible to Dim the column name and make it a variable and...
|
by: Sakcee |
last post by:
python provides a great way of dynamically creating fuctions calls and
class names from string
a function/class name can be stored as string and called/initilzed
e.g
def foo(a,b):
return...
| |
by: sean.scanlon |
last post by:
can someone help understand how i can could access a struct field
dymanically like: foo->fields ?
when i try to compile this i get the following error: 'struct pwd' has
no member named 'fields'...
|
by: vega80 |
last post by:
Hi.
I have a problem with assigning an onkeypress-function to dynamically
created input-boxes.I want to put the content of an input-field into a
tag-list when the user hits enter. This works...
|
by: likhin M |
last post by:
Hi everyone,
I am developing a webpage using only javascript.And I am dynamically creating buttons inside javascript as follows
document.write('<button name=""...
|
by: .Net Sports |
last post by:
I need to dynamically assign a datalist attribute upon a helper
function receiving data from a querystring. If a user picks a certain
region, i need the datalist to display its back color, or any...
|
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,...
|
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...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
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,...
|
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...
|
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...
|
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 ...
| |