phpstudent111 Posted March 18, 2009 Share Posted March 18, 2009 I am trying to search with a SELECT statement (mySQL) and have 8 variables I would like to include in the WHERE clause of my statement. (ie. $mymodel=model.id AND $mycolor=color.id, etc.) I'd like the variable to not be included in the WHERE statement if they are null but I am really not sure how to do this. Please let me know if you have any ideas...below is the code I have now....Thanks! <?ob_start(); ?> <!doctype html public"-//W3C//DTD HTML 4.0 //EN"> <html> <title>A/J Software Solutions-Search Results</title> <body bgcolor="#CCCCCC"> <div id="menu" align="center"> <table border="3" bordercolor="000066" valign="top" align="center"> <td> <a href="login_success.php">Search Inventory<a /> </td> <td><a href="insert.php">Add Inventory<a /> </td> <td><a href="edit.php">Edit Inventory<a/></td> <td><a href="delete.php">Delete Inventory<a /> </td> </div> <h1 align="center"> A/J Software Solutions</h1> <h2 align="center"> Inventory Management System</h2> <table id="delete" align="center"> <br><br><br> <tr><strong>Results:</strong></tr> <br><br><br> <?php ob_start(); $host="97.74.31.200"; $username="jwalkow1"; $password="Starpoint10"; $db_name="jwalkow1"; //connect to server mysql_connect("$host", "$username", "$password", 1, 131072)or die("Unable to Connect"); mysql_select_db("$db_name")or die("Cannot Select Database"); //defining variables $mymodel=$_POST['mymodel']; $mymanufacturer=$_POST['mymanufacturer']; $myyear=$_POST['myyear']; $mydoors=$_POST['mydoors']; $mydealercost=$_POST['mydealercost']; $myretailprice=$_POST['myretailprice']; $mycolor=$_POST['mycolor']; $myinteriorcolor=$_POST['myinteriorcolor']; $query="SELECT car.id , model.manufacturer , model.modelname , car.year , color.color_name , interior_color.interior_color , car.doors , car.retailprice , car.dealercost , transmission_type.transmission_type FROM car INNER JOIN model ON (car.model_id=model.id) INNER JOIN color ON (car.color_id=color.id) INNER JOIN interior_color ON (interior_color.id=car.interior_color_id) INNER JOIN transmission_type ON (car.transmission_type_id=transmission_type.id) WHERE $mymodel=model.id"; $result=mysql_query($query) or die (mysql_error()); $fields_num=mysql_num_fields($result); echo "<table border='1'><tr>"; //printing talbe headers for($i=0; $i<$fields_num; $i++) { $field=mysql_fetch_field($result); echo "<td>{$field->name}</td>"; } Link to comment https://forums.phpfreaks.com/topic/150043-null-variables-question/ Share on other sites More sharing options...
phpstudent111 Posted March 18, 2009 Author Share Posted March 18, 2009 Just to be more clear...the existing code in the WHERE clause (WHERE $mymodel=model.id" needs to be replaced....any ideas?? Link to comment https://forums.phpfreaks.com/topic/150043-null-variables-question/#findComment-788103 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.