473,569 Members | 2,880 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

assign db fields to variables with dynamically built var names

142 New Member
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("SE LECT * FROM hole ORDER BY a5");

while($row = mysql_fetch_arr ay($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($co n);


?>
[/PHP]
Mar 15 '08 #1
16 1977
ronverdonk
4,258 Recognized Expert Specialist
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
Mar 15 '08 #2
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("SE LECT * FROM hole ORDER BY a5");

while($row = mysql_fetch_arr ay($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($co n);


?>
[/PHP]
This is untested (just some logic)
[php]
$_i = 0;
$_a = array();
while($_row = mysql_fetch_arr ay($_res))
{
$_a[$_i] = $_row['col'];
++$_i;
}
[/php]
Mar 15 '08 #3
ronverdonk
4,258 Recognized Expert Specialist
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
Mar 15 '08 #4
webandwe
142 New Member
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.
Mar 15 '08 #5
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.
Mar 15 '08 #6
webandwe
142 New Member
I am testing it but for some reason it does not want to go...
Mar 15 '08 #7
Markus
6,050 Recognized Expert Expert
I am testing it but for some reason it does not want to go...
Post what youre using
Mar 15 '08 #8
webandwe
142 New Member
[PHP]
<?php
$con = mysql_connect(" l*****","*****" ,"*****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db ("****datebase* ****", $con);

$result = mysql_query("SE LECT * FROM hole ORDER BY a5");

$i = 0;
$a = array();
while($row = mysql_fetch_arr ay($result))
{
$a[$i] = $row['a5'];
++$i;
}

mysql_close($co n);
////Testing
echo "$a1 $a2 $a3 ";

?>
[/PHP]
Mar 15 '08 #9
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("SE LECT * FROM hole ORDER BY a5");

$i = 0;
$a = array();
while($row = mysql_fetch_arr ay($result))
{
$a[$i] = $row['a5'];
++$i;
}

mysql_close($co n);
////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]
Mar 15 '08 #10

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

Similar topics

8
6098
by: Corey Lubin | last post by:
someGlobal=1 class Original: def foo(self): # Make use of someGlobal from original import * someGlobal=2
4
8984
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 added a sample of that below (there would be many more rows). I'm wondering if there is a way to dynamically generate the variable names (ie:...
4
12554
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)"; document.getElementById('myelement') = new Function("myfnc(param1,param2,param3)");
13
2300
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 reassign the value to this new variable? Because I have a long list of the above, and I wish to loop thru it, instead of assigning it one by one.
5
2938
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 a+b
9
5699
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' is there a way to treat fields as the member name of the struct?
1
7481
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 fine the first time (when the input-field is created in a non-dynamical way). The next input-field is created dynamically by a function that is called...
6
1816
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="" onclick="">button1</button>'); For each button I am creating , I have to use different names.I have tried by using a javascript string variable to hold the name of the...
4
2189
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 of its other objects , as a certain color or css style <HeaderStyle BackColor="<%= ssponcont %>"</HeaderStyle> ....doesnot work as a Parser...
0
7703
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
7619
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...
0
7930
Oralloy
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. ...
0
8138
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
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
6290
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
5228
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...
1
2118
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
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.