Jump to content

[SOLVED] a dynamic SELECT statement


bioTINMAN

Recommended Posts

hi, im new to php and as well as this place, i was wondering if there was a way to replace:

 

$insert=mysql_query("SELECT * FROM login where value1=5");

 

with:

 

$value='value1=\'$val\' ';

$insert=mysql_query("SELECT * FROM login where $value");

 

-------

 

the above thing works when we have something like $value='value1=5'; but when i insert a variable, there seems to be a problem.

 

thanks!

Link to comment
https://forums.phpfreaks.com/topic/83191-solved-a-dynamic-select-statement/
Share on other sites

<?php

if(mysql_connect(localhost,root,pass))

echo "in";

if(mysql_select_db(dump))

echo "into db";

 

$date=5;

 

 

$TOTO='date=\'$date\'';

 

echo $TOTO;

 

$insert=mysql_query("SELECT * FROM login where $TOTO");

 

if($insert)

echo "yes";

 

if($check=mysql_fetch_array($insert))

echo "yes again";

 

 

 

?>

 

==========

 

pardon the variable names, and those echo's - i was trying to check where the problem is. If i replace the $TOTO with date=5, it works. but with $TOTO it simply shuts off.

The idea is for a search form, one in which the user will choose some of the many fields on the page. I thought if i could use a variable like that of $TOTO,  ;D and keep adding field names into it, as the user choses them, then the mysql search query might be more compact.

 

or is there another way?

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.