PHP - Moved: Get Rel=id And Pass To Query
This topic has been moved to Ajax Help.
http://www.phpfreaks.com/forums/index.php?topic=353002.0 Similar TutorialsI am working on a room availability calendar that has links for each day. When you click on a link it passes the day month and year in the URL to another page like this: echo "<td class=\"today\"> <a href=\"status.php?month=$month&day=$day_num&year=$year\">$day_num</a> </td>\n"; I can see that the correct information is being passed through the URL like this: Code: [Select] .../status.php?month=12&day=9&year=2010 Then the information is supposed to be passed to the MySQL query, but here is my question: How do I do this? I have a DB table set up, but the query is currently returning a blank page. Here is my current query: // connects to server and selects database. include ("../includes/dbconnect.inc.php"); // table name $table_name = "availability"; // query database for events $result = mysql_query ("SELECT id FROM $table_name WHERE month=$month AND year=$year AND day=$day_num LIMIT 1") or die(); if (mysql_num_rows($result) > 0 ) { while($row = mysql_fetch_array($result)) { extract($row); echo "<h1>Current availability for ".$row['month'] . "/" . $row['day'] . "/" . $row['year'] . "</h1>"; echo " <ul>"; echo " <li>Earth Room: " . $row['earth_room'] . "</li>"; echo " <li>Air Room: " . $row['air_room'] . "</li>"; echo " <li>Fire Room: " . $row['fire_room'] . "</li>"; echo " <li>Water Room: " . $row['water_room'] . "</li>"; echo " </ul>"; } } else { echo " <ul>"; echo " <li>Currently no reservations.</li>"; echo " </ul>"; } Any help is appreciated. Thanks, kaiman SQLITE has syntax like ' WHERE MATCH ( 'colname : "one two" )' //My pdo sql query $sql .= MATCH 'colname : "?" )'; $pdo->bindValue(1,$text);` But Pdo placeholders can't have quotes around them. So this does not work. I tried a million variations of the placeholder syntax "?" "" ? "" """ ? """ \" ? \" . But nothing works. Errors I get : General error: 1 near "?" | 25 column index out of range . Also for this query : MATCHÂ ( names: ? AND categoryids: ? ) , the error is: `General error: 1 unrecognized token: ":"` Would really love some help here.. Thanks Edited March 29, 2019 by requinix removing bad styling How can I make my on change in the form pass through the year thats been selected, then use that in the second query? Code: [Select] <select name="mySelect" onchange=""> <?php $result= mysql_query('SELECT DISTINCT Year FROM MonthlySales'); ?> <?php while($row= mysql_fetch_assoc($result)) { ?> <option value="<?php echo htmlspecialchars($row['Year']);?>"> <?php echo htmlspecialchars($row['Year']); ?> </option> <?php } ?> </select> <?php $query="SELECT * FROM MonthlySales WHERE Year = PASS YEAR SELECTED VARIABLE TO THIS BIT HERE"; $results = mysql_query ( $query, $conn); I have some data in a table and some of it is Artist names stored as "Last, First" I need to be able to have the script search weather or not someone types "last, first" or "first last". Any ideas? Here's my code: <html> <head> <title>search script</title> </head> <body> <form name="form" action="search.php" method="get"> <input type="text" name="q" /> <input type="submit" name="Submit" value="Search" /> </form> <?php // Get the search variable from URL $var = @$_GET['q'] ; $trimmed = trim($var); //trim whitespace from the stored variable // rows to return $limit=100; // check for an empty string and display a message. if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; } // check for a search parameter if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } //connect to your database ** EDIT REQUIRED HERE ** mysql_connect("localhost","username","password"); //(host, username, password) //specify database mysql_select_db("mydb") or die("Unable to select database"); //select which database we're using // Build SQL Query $query = "select * from songs where Title like \"%$trimmed%\" or Artist like \"%$trimmed%\" order by Title"; // EDIT HERE and specify your table and field names for the SQL query $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); // If we have no results, offer a google search as an alternative if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; } // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched for echo "<p>You searched for: "" . $var . ""</p>"; // begin to show results set echo "Results"; $count = 1 + $s ; // now you can display the results returned echo "<table border=1>"; while ($row= mysql_fetch_array($result)) { $title = $row["Title"]; $artist = $row["Artist"]; $number = $row["Number"]; echo "<tr><td>$count.)</td><td>$title</td><td>$artist</td><td>$number</td></tr>" ; $count++ ; } echo "</table>"; $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>  "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 20 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?> </body> </html> This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=317004.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=343031.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=357747.0 I work with a large codebase and I have this situation come up fairly often:
the legacy class has large objects such as:
$design->motor->dimensions->a; $design->motor->dimensions->bd; $design->specifications->weight; $design->data->height; //etcWhen I create a new class, that class sometimes operates on the specific data, so say: class MyClass { public function compute($weight, $height, $a) { //stuff } } //and I call this for example as such: (new MyClass())->compute($design->specifications->weight, $design->data->height, $design->motor->dimensions->a);CONS: Potential issue: if design specs change and I need to change things parameters in "compute" function, I need to "re-key" the variables I pass to the function, and adjust things accordinly in MyClass as wel. PROS: only the exact data is being passed, and this data can come from anywhere it is viable, so in effect the function is fairly well separated, I think. Alternative option for me is to pass the entire design object, i.e class MyClass { public function compute(&$design) //can also be done via DI through a setter or constructor. { print $design->specifications->weight; print ($design->data->height + $design->motor->dimensions->a); //stuff } } (new MyClass())->compute($design);PROS: In this case when things change internally in which variables are needed and how things are computed, I only need to change the code in compute function of the class itself. CONS: MyClass now needs to be aware of how $design object is constructed. When it comes to this parameter passing, and Dependency Injection like this in general, does Computer Science advocate a preference on this issue? Do I pass the entire object, or do I pass only the bits and pieces I need? I'm trying to get a simple table to display and am not sure how to make it happen. Table will have just 2 columns. A TIME and an EVENT. What I want to have happen is for the first row to show the TIME and next to that, the EVENT. If a TIME has more than one event going I want the next row to show an empty first cell and then the second event below the first. If I set up the loop the only way I know how (so far) it would also output the TIME value again and again as many times as there were events for that same time. For example what I don't want is: 9:15 Sunday School 9:15 Nursery Available What I do want is: 9:15 Sunday School Nursery Available Thanks. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=347360.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=359179.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=329559.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=311010.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=344191.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=347365.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=348956.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=311619.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=353189.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=325846.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=306079.0 |