Jump to content

Need help with functions mysql_fetch_assoc


WebsoluteSW

Recommended Posts

Hello, I'm working onthe below peice of code basically when i call a table from the database I dont want to have to write all the code each time hence the function, The only part I'm having trouble with is specifying the column heading without hard codeing it see below.

 

mysql_fetch_assoc

 

function return_table_item($item, $table)
{
$table_item="SELECT $item FROM $table";
$table_item_results =mysql_query($table_item);
 
while ($item_return=mysql_fetch_assoc($table_item_results)){
echo '<a href=' . $item_return['$item'] . '.php target="menu_results"><li>' . sanitize_text_from_tables($item_return['$item']]) . '</li></a>';
}
 
how can I request the $item column using the function variable $item.
 
Any help appreciated.
echo '<a href=' . $item_return[$item] . '.php target="menu_results"><li>' . sanitize_text_from_tables($item_return[$item]]) . '</li></a>';

 

PHP Parse error:  syntax error, unexpected ']' in /home/quotegen/public_html/QuoteGenV4/library/class_lib.php on line 19

 

Any ideas?

No problem, glad to help.  :happy-04:

 

Side note:

Perhaps you are already aware of this, but the mysql_ functions have been depreciated. More information about the alternatives can be found here:

http://www.php.net/manual/en/mysqlinfo.api.choosing.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.