Jump to content

using $action in a string


brown2005

Recommended Posts

$action = $_GET['action'];

 

$url_sql = mysql_query("SELECT * FROM z_sponsors_adverts_hits_'.$action.' WHERE sponsors_adverts_hits_'.$action.'_type='0' AND sponsors_adverts_hits_'.$action.'_user='$config_ip' AND sponsors_adverts_hits_'.$action.'_advert='$website_id'", $connection);

 

$url_rows = mysql_num_rows($url_sql);

 

echo"rows = $url_rows";

 

like that?

this is incorrect syntax:

$sql = "SELECT * FROM $action WHERE $action_user = 'username';";

 

Use it like this instead:

 

$sql = "SELECT * FROM {$action} WHERE {$action}_user='username'";

 

you had an extra ; in your query and use { and } around your variables.

a tip, when you have simple strings: $action , and having double quotations, you dont have to stop the quotation using '..', instead, simply place them like:

"SELECT * FROM z_sponsors_adverts_hits_$action WHERE sponsors_adverts_hits..."

as well as leave out the ; symbol, you dont need those in the query, it think thats about it...

 

EDITED, do you have to do this:

"SELECT * FROM {$action} WHERE {$action}_..."?

i thought $action would work with "

Ted

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.