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
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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.