PHP - Compare Mysql Row Value To Php Variable
Hi again everyone,
I am trying to compare a php variable to the value of a row in mysql, but keep getting the following error: Code: [Select] Wrong perameter count for mysql_result() What syntax would I use to accomplish this? Here is my code: // connects to server and selects database. include ("../includes/dbconnect.inc.php"); // table name $table_name = "availability"; // split up date into 3 separate fields $date = "12/25/2010"; $date_split = explode("/", $date); $month = $date_split[0]; $day = $date_split[1]; $year = $date_split[2]; // check if earth room is already reserved $taken = "Reserved"; $sql = "SELECT earth_room FROM $table_name WHERE month='$month' AND day='$day' AND year='$year' LIMIT 1"; $result = mysql_query($sql) or trigger_error("A mysql error has occurred!"); $row = mysql_result($result); if($row == $taken){ echo "Room Already Reserved"; } else{ echo "Room Available"; } Thanks for the help, kaiman Similar TutorialsI run an article directory. I was wondering how I could check an article that is currently pending review against published articles in our database. What I am looking to do is to place the content of the body in the pending article into a variable. That much is easy and I know how to do that. Then I would like to use that variable to compare against other content in our database and have it output a percentage of how close it is to any other article already published in our database. Any direction our guidance with this would be so greatly appreciated. Thanks! I typically only use the first two solutions. Is there anything wrong with the third? Is there any more streamlined way to do it?
function f1($x){return $x*1;} function f2($x){return $x*1;} $x=2;$y=1; if(f1($x)>f2($y)){echo(f2($y)."\n");} // or $f2_y=f2($y); if(f1($x)>$f2_y){echo($f2_y."\n");} // or if(f1($x)>$f2_y=f2($y)){echo($f2_y."\n");} Hey, I'm new to this stuff. But I'm calling a Table with a list of products, I want people to be able to compare the products they checked. what is the best way of doing this with the code below? I put "blah" for everything except for the compare table and calls. This code seemed to work the best for the look I wanted for it. They all call the checkbox from 'Compare' in the mysql table. Thanks! $result = mysql_query("SELECT * from Compare_Tool ORDER BY Blah ASC"); //Table starting tag and header cells echo "<table border='1'><tr><th>Compare</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th></tr>"; while($row = mysql_fetch_array($result)){ ?> <tr> <td align="center"><input name="checkbox[]" type="checkbox" Compare="checkbox[]" value="<? echo $row['Compare']; ?>"></td> <td ><? echo $row['blah']; ?></td> <td ><? echo $row['blah']; ?></td> <td ><? echo $row['blah']; ?></td> <td ><? echo $row['blah']; ?></td> <td ><? echo $row['blah']; ?></td> <td ><? echo $row['blah']; ?></td> <td ><? echo $row['blah']; ?></td> <td ><? echo $row['blah]; ?></td> <td ><? echo $row['blah]; ?></td> <td ><? echo $row['blah]; ?></td> <td ><? echo $row['blah]; ?></td> </tr> <?php } echo "</table>"; ?> Hi All, I'm working on PHP scripts to interact with a web hosted MySQL DB for an Android Application. Simply what I am trying to do is in the PHP script is run a SELECT statement which will return the value of a column, UserType, and compare the result of this to a string, which will then execute code depending on it's value. This user type can only be either 'student' or 'lecturer'. Any help with this would be much appreciated. <?php require "init.php"; $user = $_GET["userID"]; #Selects column account type where the idNum equals $user which is passed from my app. $sql1 = "select accountType from user_info where idNum = '$user'"; $result1 = mysqli_query($con,$sql1); $row1 = mysqli_fetch_assoc($result1); #This is where I am stuck. Simply, I am trying to run the code in the loop where the result of $sql1 equals 'Student'. The else will run if it is not #student and therefore is 'Lecturer'. I'm also not sure if my code inside the IF is fully correct either as it's not running that far. if($row1['accountType'] == 'Student') { $sql2 = "select courseCode from user_info where idNum = '$user'"; $result2 = mysqli_query($con,$sql2); $row2 = mysqli_fetch_assoc($result2); $sql3 = "select * from module_details where classListCourseCode = '".$row2['courseCode']."'"; $result3 = mysqli_query($con,$sql3); $response = array(); while($row = mysqli_fetch_array($result3)) { array_push($response,array("moduleID"=>$row[0],"lecturerID"=>$row[1],"moduleName"=>$row[2],"classListCourseCode"=>$row[3])); } echo json_encode(array("server_response"=>$response)); } Thanks in advance. I want to perform a query which returns a subset of the fields in a table. One particular mySQL field is VARCHAR I have a query like this: $query = mysql_query("SELECT * FROM table WHERE code LIKE '3%') ; It's my understanding this should return all values which begin with "3", but it only returns about a dozen of the values 3, 30-39, 300-399, etc. (It works with string fields, but this field contains numerals.) Any help appreciated. thanks, Tom Has anyone got any script or refence to a tut where i can find a script that compares two mysql database (current) and outdated db and then takes the current db and updates the outdated one to match accordingly. Thanks Hi, I need to compare records in a table based on the 'datetime' field, like if the difference between time is less than 15min. need to combine the records(rows) as a single resultant row until the time difference between them is less than 15min and when a record's time difference is >15min that should return as another row and so on. Please find following sample table and the required output format Sample Table: Code: [Select] ID NAME DATETIME 1 aaa 2011-10-10 06:30:00 2 bbb 2011-10-10 06:33:00 3 ccc 2011-10-10 06:38:00 4 ddd 2011-10-10 06:40:00 5 eee 2011-10-10 07:10:00 6 ffff 2011-10-10 07:14:00 7 sss 2011-10-10 08:16:00 8 jjj 2011-10-10 08:26:00 9 kkk 2011-10-10 08:28:00 10 mm 2011-10-10 09:46:00 11 ppp 2011-10-10 09:49:00 12 qqq 2011-10-10 09:52:00 Output Needed : Code: [Select] IDs START DATETIME END DATETIME 1,2,3,4 2011-10-10 06:30:00 2011-10-10 06:40:00 5,6 2011-10-10 07:10:00 2011-10-10 07:14:00 7,8,9 2011-10-10 08:16:00 2011-10-10 08:28:00 10,11,12 2011-10-10 09:46:00 2011-10-10 09:52:00 You can see 1st row in the output table having IDs 1,2,3,4 coz the time difference between them is less than 15minutes (it doesn't means time difference between start and end; it is actually the time difference between current record and previous one ; ie; ID-1 and ID-2 have difference less than 15min and ID-2 & ID-3 have difference less than 15min and ID-3 & ID-4 have difference less than 15min, so those 4 records combine together as a single row also shows their start time and end time. Then you can see diff between ID-4 and ID-5 is greater than 15 min so it should display as new row, and so on) How can I acheive above Output with mysql query ?? Please help.. I am trying to allow the user to update a variable he chooses by radio buttons, which they will then input text into a box, and submit, to change some attributes. I really need some help here. It works just fine until I add the second layer of variables on top of it, and I can't find the answer to this question anywhere. <?PHP require('connect.php'); ?> <form action ='' method='post'> <select name="id"> <?php $extract = mysql_query("SELECT * FROM cars"); while($row=mysql_fetch_assoc($extract)){ $id = $row['id']; $make= $row['make']; $model= $row['model']; $year= $row['year']; $color= $row['color']; echo "<option value=$id>$color $year $make $model</option> ";}?> </select> Which attribute would you like to change?<br /> <input type="radio" name="getchanged" value="make"/>Make<br /> <input type="radio" name="getchanged" value="model"/>Model<br /> <input type="radio" name="getchanged" value="year" />Year<br /> <input type="radio" name="getchanged" value="color" />Color<br /><br /> <br /><input type='text' value='' name='tochange'> <input type='submit' value='Change' name='submit'> </form> //This is where I need help... <?PHP if(isset($_POST['submit'])&&($_POST['tochange'])){ mysql_query(" UPDATE cars SET '$_POST[getchanged]'='$_POST[tochange]' where id = '$_POST[id]' ");}?> I am trying to extract a value that is stored in a variable from my database. It will not work with how I have the code written. If I replace .$tournament with what I want it to find, it will give me the correct result. ANy suggestions? Below is my code: Code: [Select] $result = mysql_query("SELECT id FROM `2012_tournaments` WHERE tournament = .$tournament"); while($row = mysql_fetch_array($result)) { echo $row['id']; }; Hi, I am very new to this. Can someone point me in the right direction please. I have mysql database which contains a variable $pricelist. The client is registered via an admin area. Is sent the login (email and password). Once logged in they see their details. All this works fine. Each client will have a different price list, total number of price lists options will be about 10. In the database the variable will return pricelist1.pdf or pricelist2.pdf etc. This is also OK. My question is how do I provide a hyperlink to the pricelist1.pdf file (which is located on the server) for the client to view and download if they wish? Thanks in advance. I have a mysql field that I want to store a php variable in and then retrieve it.
Example:
Color table has the field named colorBackground with the value of #FF0000
CSS table has the field named cssBackground with the value of .background { background-color: #444444; }
What I want to do is make Color/colorBackground a variable {{$backgroundcolor = rsColor['colorBackground']
Then I want to change the CSS/cssBackground value to .background { background-color:$backgroundcolor; }
Creating the $backgroundcolor works fine. I'm just not sure how to put the $backgroundcolor in my CSS/cssBackground field.
You guys are great, thanks again for the help last week. Now I almost got this working but a small hiccup. here is my code: Code: [Select] <?php include("config.php"); $my_t=getdate(date("U")); $my_t1=$my_t[weekday]; $result = mysql_query("SELECT * FROM tourney where day_of_week = '$my_t1'") or die(mysql_error()); if ($result == '') echo "<br>Empty Set\n"; print_r ($my_t1); This prints correctly Code: [Select] while ($result = mysql_fetch_array($result,MYSQL_ASSOC)) { This is my error. "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /hermes/bosweb/web017/b172/ipg.dswdesignsnet/pp4c/charity1.php on line 8" Code: [Select] print "<b>Starting Time: <br></b>".$row{'start_time'}."<br><b>Tournament: </b><br>".$row{'tourney'}."<br><b>Buy-in: <br>".$row{'buy_in'}."<br><b>Starting Chips: <br>".$row{'start_chips'}."</font><p>"; This prints headers correctly, but no variables. Code: [Select] } mysql_close($dbh); ?> What did I forget to do or what did I do wrong. I'm still learning mysql and php. Hi anyone here know how to insert $GET variable into mysql, i don't know how to put this variable between curly bracket, when i put on top insert query, i got error 'Could not insert admin'...please help Code: [Select] <?php mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("healthsystem") or die(msql_error()); [color=red]//GET varibable $id = $_GET['id'];[/color] // file properties $file = $_FILES['image']['tmp_name']; if (!isset($file)) echo "Please select an image"; else { $image = addslashes(file_get_contents($_FILES['image']['tmp_name'])); $image_name = addslashes($_FILES['image']['name']); $image_size = getimagesize($_FILES['image']['tmp_name']); if ($image_size==FALSE) echo "That's not an image."; else { $insert = "INSERT INTO image_tbl(m_id,name,image) VALUES ('$id','$image_name','$image')"; $insert2=mysql_query($insert) or die("Could not insert admin"); print "Personal Wellness Successfully Submitted"; } } ?> hello can anyone help me how to insert GET variable into mysql <?php $page_title = 'Personal Wellness'; include ('template/header.inc'); include_once('config.php'); $id = $_GET['id']; if(isset($_POST['submit'])) //if submit was pressed { if(strlen($_POST['height'])<1) //if there was no height { print "You did not enter a height."; } else if(strlen($_POST['weight'])<1) //no weight { print "You did not enter a weight."; } else if(strlen($_POST['bodyfat'])<1) //no bodyfat { print "You did not enter a Body Fat Range"; } else if (strlen ($_POST['bodywater'])<1) //no bodywater { print "You did not enter a Body Water Range"; } else if( strlen($_POST['musclemass'])<1) //no musclemass { print "You did not enter a Muscle Mass"; } else if (strlen ($_POST['physiqueratt'])<1) //no physiqueratt { print "You did not enter a Physique Ratings"; } else if (strlen ($_POST['bonemass'])<1) //no bonemass { print "You did not enter a Bone Mass"; } else if (strlen ($_POST['bmr'])<1) //no bmr { print "You did not enter a BMR"; } else if (strlen ($_POST['basalmetabolic'])<1) //no basalmetabolic { print "You did not enter a Basal Metabolic Age"; } else if (strlen ($_POST['visceralfat'])<1) //no visceralfat { print "You did not enter a Visceral Fat"; } else if(strlen($_POST['registrationmonth'] && $_POST['registrationday'] && $_POST['registrationyear'])<1) // no date { print "You did not enter a date of birth"; } else //all fields met { $id=$_GET['id']; $height=$_POST['height']; $weight=$_POST['weight']; $bodyfat=$_POST['bodyfat']; $bodywater=$_POST['bodywater']; $musclemass=$_POST['musclemass']; $physiqueratt=$_POST['physiqueratt']; $bonemass=$_POST['bonemass']; $bmr=$_POST['bmr']; $basalmetabolic=$_POST['basalmetabolic']; $visceralfat=$_POST['visceralfat']; $date=$_POST['registrationyear'] . '-' . $_POST['registrationmonth'] . '-' . $_POST['registrationday']; $insertadmin="INSERT into personalwelness (m_id,height,weight,body_fat,body_water,muscle_mas s,physique_ratt,bone_mass,bmr,basal_metabolic,visc eral_fat,evaluation_date) values ('$id','$height','$weight','$bodyfat','$bodywater','$mus clemass','$physiqueratt','$bonemass','$bmr','$basa lmetabolic','$visceralfat','$date')"; //registering admin in databae echo $insertadmin; $insertadmin2=mysql_query($insertadmin) or die("Could not insert admin"); print "Personal Wellness Successfully Submitted"; } } ?> <form method="post" class="form" action="<?php echo $_SERVER['PHP_SELF'];?>"> <fieldset><legend>Enter Personal Wellness Information in the form below:</legend> <table width="80%" border="0"> <tr> <td width="16%">Height(CM)</td> <td width="2%">:</td> <td width="82%"><label for="height"></label> <input type="text" name="height" id="height" value="<?php if (isset($_POST['height'])) echo $_POST['height'];?>" /></td> </tr> <tr> <td>Weight(KG)</td> <td>:</td> <td><label for="weight"></label> <input type="text" name="weight" id="weight" value="<?php if (isset($_POST['weight'])) echo $_POST['weight'];?>" /></td> </tr> <tr> <td >Body Fat Range</td> <td>:</td> <td><label for="body fat"></label> <input type="text" name="bodyfat" id="bodyfat" value="<?php if (isset($_POST['bodyfat'])) echo $_POST['bodyfat'];?>" ></td> </tr> <tr> <td>Body Water Range(%)</td> <td>:</td> <td><label for="bodywater"></label> <input type="text" name="bodywater" id="bodywater" value="<?php if (isset($_POST['bodywater'])) echo $_POST['bodywater'];?>"/></td> </tr> <tr> <td>Muscle Mass</td> <td>:</td> <td><label for="musclemass"></label> <input type="text" name="musclemass" id="musclemass" value="<?php if (isset($_POST['musclemass'])) echo $_POST['musclemass'];?>"></td> </tr> <tr> <td>Physique Ratings</td> <td>:</td> <td><label for="physiqueratt"></label> <input type="text" name="physiqueratt" id="physiqueratt" value="<?php if (isset($_POST['physiqueratt'])) echo $_POST['physiqueratt'];?>"></td> </tr> <tr> <td>Bone Mass</td> <td>:</td> <td><label for="bonemass"></label> <input type="text" name="bonemass" id="bonemass" value="<?php if (isset($_POST['bonemass'])) echo $_POST['bonemass'];?>" /></td> </tr> <tr> <td>BMR</td> <td>:</td> <td><label for="bmr"></label> <input type="text" name="bmr" id="bmr" value="<?php if (isset($_POST['bmr'])) echo $_POST['bmr'];?>"/></td> </tr> <tr> <td>Basal Metabolic Age</td> <td>:</td> <td><label for="basalmetabolic"></label> <input type="text" name="basalmetabolic" id="basalmetabolic" value="<?php if (isset($_POST['basalmetabolic'])) echo $_POST['basalmetabolic'];?>"></td> </tr> <tr> <td>Visceral Fat</td> <td>:</td> <td><label for="visceralfat"></label> <input type="text" name="visceralfat" id="visceralfat" value="<?php if (isset($_POST['visceralfat'])) echo $_POST['visceralfat'];?>"></td> </tr> <tr> <td>Evaluation Date</td> <td>:</td> <td> <?php echo date_picker("registration")?></td> </tr> </table> </fieldset> <div align="center"><input type="submit" name="submit" value="Submit" /> </div> </form> <?php function date_picker($name, $startyear=NULL, $endyear=NULL) { if($startyear==NULL) $startyear = date("Y")-100; if($endyear==NULL) $endyear=date("Y")+50; $months=array('','January','February','March','Apr il','May', 'June','July','August', 'September','October','November','December'); // Month dropdown $html="<select name=\"".$name."month\">"; for($i=1;$i<=12;$i++) { $html.="<option value='$i'>$months[$i]</option>"; } $html.="</select> "; // Day dropdown $html.="<select name=\"".$name."day\">"; for($i=1;$i<=31;$i++) { $html.="<option $selected value='$i'>$i</option>"; } $html.="</select> "; // Year dropdown $html.="<select name=\"".$name."year\">"; for($i=$startyear;$i<=$endyear;$i++) { $html.="<option value='$i'>$i</option>"; } $html.="</select> "; return $html; } ?> <?php include ('template/footer.inc'); ?> Hi im trying to set that if a certain statement is echoed then set variables to an amount but they dont seem to be inserting into the table Code: [Select] if ($match_qutoe == "".$username2." lands a uppercut"){ $points = "4"; $fighter = $username2; } $query = mysql_query("INSERT INTO fight (bluecornerusername, redcornerusername, round, fighter, points, statement) VALUES('$username', '$username2', '$round', '$fighter', '$points', '$match_quote')"); its only $points and $fighter that are not inserting Thanks Can anyone point out how to write a MySQL query with a PHP variable in the WHERE clause. I've tried {} {'xx'} and () and it still doesn't work. Here is the code <?php ini_set('display_errors',1); error_reporting(E_ALL|E_STRICT); include ("include/connect.php"); include ("include/session.php"); $username = $session->userinfo['username']; $result = mysql_query("SELECT email FROM customer WHERE user = {'$username'} "); while($row = mysql_fetch_array($result)) { $custemail = $row['email']; } echo "Session username: " . $username . ""; echo "Session customer email: " . $custemail . ""; ?> So I'm trying to show the email address for a record that matches the username of the user logged in. I really appreciate the help. Hey, I'm trying to save a MySQL-Link source as an instance variable in my query class. The problem is that MySQL sees it as an invalid MySQL-Link (supplied argument is not a valid MySQL-Link resource). What I'm I doing wrong? //Walle Code: [Select] private $connection; //Construct public function __construct(&$connection) { $this->connection = $connection; } //Where the error occurs public function exe_query($sql) { $result = mysql_query($sql, $this->connection); if(!$result) { throw new Exception(mysql_error()); } return $result; } hey all so I have this bit down: Code: [Select] $query="SELECT `2010 Region Code` AS codes FROM locations"; $results = mysql_query($query); $options=""; $options = "<select location='codes'>"; while($nt=mysql_fetch_assoc($results)) { $thing=$nt["codes"]; $options.="\r\n<option value ='{$nt['codes']}'> {$nt['codes']}</option>"; } $options .="\r\n</select>"; echo $options; what I'm trying to do is grab the selection from the drop down and display it as a table (the sql query would be extended should we manage to figure this one out I've tried Code: [Select] echo"<form name='LOCATIONS' action='".$_SERVER['PHP_SELF']."' target='iframe' method='post'>"; any ideas? I have a form passing user's search term, ie name. $pname = mysql_real_escape_string($pname; Not sure on proper syntax to include this in my select statement. I also want it to return for partial string matched, like 'mik' for 'mike': $result = mysql_query( "SELECT * FROM guest WHERE name like '$pname'" ); |