Web Hosting Talk







View Full Version : MySql query help. [Modernbill]


chuchuman
01-26-2006, 11:59 AM
Im in need of your help again guys.
I am trying to get info stored on mysql database to be shown on a php page. I guess il need to run query, but im still a beginner. I tried everything i can, with no luck.

Someone tell me like a template query command or something, so that i can get this to work.

If you dont understand what im saying, il explain:

Lets say iv got database name: test_test
I want to get the information stored inside the table: t_table
In this table the information is inside the field under: t_column

I want to get whatever text is inside the field t_column, to be shown on my php page.

Any solutions??:bawling:

[For those wondering why i need this: im trying to edit modernbill, i want to get the contents i enter in the features section to be shown on the order form, or something similar, because i want the user to see like a summery of whats included, on top of the order form]

Korvan
01-26-2006, 12:20 PM
//open your database connection
$link = mysql_connect($user, $pass, $server);
$db = mysql_select_db("test_test");
$sql = "SELECT t_column FROM t_table";
if(!($result = mysql_query($sql)))
{
//error, handle it in here

}
else
{
//success
while(($arr = mysql_fetch_assoc($result)))
{
//now columndata contains an array of all the values in t_column.
$columndata[] = $arr['t_column'];

}
}

chuchuman
01-26-2006, 03:29 PM
thanks for the answer. I dont see any errors, but i dont see the output on the php page:(

What's missing?

Flash-matic
01-26-2006, 03:34 PM
That script is not outputting anything yet. You need to write the rest he gave you the way to retreive it.

chuchuman
01-26-2006, 04:30 PM
That script is not outputting anything yet. You need to write the rest he gave you the way to retreive it.
ok.
Could you please point me in the direction of outputing it? I have not done this before.:puke:

Confined
01-26-2006, 05:20 PM
print_r($columndata);


will print it all out for you, and it will show you the children of the parents if there are any as an array.

t_column doens't have any children you can just do

echo $columndata;


let me know if that works.

chuchuman
01-26-2006, 05:51 PM
Thanks for the tip coil.

Its showing some of the contents now. It shows:

Array ( [0] => testting feature [1] => TEsting content )
I actually tried the echo funstion before. No luck

Im doing this in modernbill. if you used modernbill you myt find the code familiar. Im trying to pull the contents of the features bit of each product to show on the order form.

The code im using is:



<?
$link = mysql_connect("localhost", "db_user", "db_pass");
$db = mysql_select_db("db_modernbill");
$sql = "SELECT feature_comments FROM package_feature WHERE pack_id = '$type3_package'";
if(!($result = mysql_query($sql)))
{
//error, handle it in here

}
else
{
//success
while(($arr = mysql_fetch_assoc($result)))
{
//now columndata contains an array of all the values in t_column.
$columndata[] = $arr['feature_comments'];

}
}
print_r($columndata);
?>

Another point: The output only shows when i remove
WHERE pack_id = '$type3_package' From the sql line.

Anything im missing??

Confined
01-26-2006, 05:54 PM
To output the testing feature, do echo $columndata[0];
//to output content, do
echo $columndata[1];


I'm not familiar with modernbill, sorry. It appears that $type3_package is not in the database, OR you are setting it incorrectly, or it's not set at all.

Do a echo $type3_package; to see if it's being set properly (given a value)