PHP - Use Query Results To Perform Multiple New Queries
Hello I have a question. I'm trying to perform multiple queries based off the results from a query. Is this possible ?
$result = mysql_query("SELECT id FROM sometable"); for each id returned $result1 = mysql_query("SELECT * FROM someothertable WHERE id=result from $result query"); Any help would be GREAT Similar TutorialsHi, I am currently working on a very detailed personal project during my vacation to keep me busy, but I have a problem, I am trying to create a unique id, without having the chance of a repetition of the id, even if its infinitely small. So I found the flickr ticket id system to be a good choice, since it was sequential and effective. My problem now is, how can I execute 2 queries simultaneously, given the hypothetical change that if I execute them with two separate queries (mysql_query), that there is the chance that another query could be executed in between the break, causing two id's to be the same. Since mysql_query can only execute a single query I am a bit stuck. I thought about possibly using CGI, but then again I have never used it, so I don't know its limitations. Can anyone suggestion anything to me for this problem, as to how I can execute two query strings in the same query. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=330871.0 I have to make a mail form (which is already coded) that will pull peoples names and email address from a database based on certain form parameters. I have the form done and am so close on finishing it up but am stuck on some mail() issues. I have the form set up to use: mail($sendTo, $theSubject, $theMessage, $headers); Using this format, I know that I can send this email to multiple recipients at once doing the following: mail('Name1 <email1@na.com>, Name2 <email2@na.com>', $theSubject, $theMessage, $headers); So I have my mySQL query all set up and it looks like so: $query="SELECT * FROM operations_forms WHERE department='$initiatedBy'"; $result=mysql_query($query); while( $row = mysql_fetch_assoc( $result ) ) { $name = $row["name"]; $email = $row["email"]; $recip = $name . " <" . $email .">, "; $sendTo = $recip; } The problem I am having is that my $sendTo variable only is passing on one record, not a combination of all of them. I am at a loss here on how to spit out all the variables and then combine them into one. I can use the above and produce an echo call that looks correct... but it doesn't function correctly on the back end. Any help? Thanks! I was just wondering if it's possible to run a query on data that has been returned from a previous query? For example, if I do Code: [Select] $sql = 'My query'; $rs = mysql_query($sql, $mysql_conn); Is it then possible to run a second query on this data such as Code: [Select] $sql = 'My query'; $secondrs = mysql_query($sql, $rs, $mysql_conn); Thanks for any help quick layout trying to accomplish Radio Boxes O O O O O O O SEARCH .............. -OK- OK is the submit button POST should be radiox (function to run) +search user select radiobox 4 and then searches xxxaaa then presses OK then POST PHP_SELF same page being used (index.php) im having an issue trying to get the radio to be selected with teh SEARCH then SUBMIT and RUN a function to perform with the DATA //later looking at trying to view it as the script in the backend is running rather then waiting for it BUT thats just me a google to find lol <?php if (isset($_REQUEST['search'])) { $search = escapeshellcmd($_REQUEST['search']); $command = '/etc/SCRIPT/BLAHLOG ' . $search; printCmd($command, true); } ?> <?php if radio3 SELECTED THEN $search = escapeshellcmd($_REQUEST['search']); $command = '/etc/SCRIPT/BLAHSQLscript ' . $search; printCmd($command, true); ?> <form> <div id="radio"> <input type="radio" id="radio1" name="radio" /><label for="radio1">BLAhscript</label> <input type="radio" id="radio2" name="radio" /><label for="radio2">BLAHTEST</label> <input type="radio" id="radio3" name="radio" /><label for="radio3">BLAHSQLscript</label> <input type="radio" id="radio4" name="radio" /><label for="radio4">BLAHTEST</label> <input type="radio" id="radio5" name="radio" /><label for="radio5">BLAHREAD</label> <input type="radio" id="radio6" name="radio" /><label for="radio6">BLAHLOG</label> <input type="radio" id="radio7" name="radio" /><label for="radio7">BLAHUSAGE</label> <input type="radio" id="radio8" name="radio" /><label for="radio8">BLAHNETWORK</label> <input type="radio" id="radio9" name="radio" /><label for="radio9">BLAH9</label> <input type="radio" id="radio10" name="radio" /><label for="radio10">BLAH10</label> </div> </form> <p> </p> <p><strong>Enter a site:</strong> <input type="text" name="search" id="search" /> <input type="submit" value="OK"/> (PUT IT IN THE SAME PAGE from the response of RADIO4 selected ---PLUS ----SEARCH) <div id="RESPONSE" style="width: 540px"></div> Complete beginner here so just really looking for pointers on where to start. Been doing a bit of bug fixing on one of our sites because the past 3 programmers we've hired have disappeared on us. The big issue I'm looking to solve is the load time of a search. Our website (Love-Rugs) is taking about 6 or 7 seconds to perform a blank search (basically a quick browse) whereas out other site (Little-Persia) takes about a second. It wouldn't be so bad if it was just the initial search but going from one page (only 10 products listed per page) to the next takes the same amount of time. There seems to be an awful lot of queries (around 130-150) on the searches - however - when using some of the search options e.g. type and fabric to refine the search the queries actually stay high but the time to process the results is reduced significantly. I don't really understand why if the queries are still high the search time is much lower unless it's to do with the number of results returned. However this does not explain why Little-Persia (which has far more products on it) takes less time as there would obviously be more results. I realize that without code this isn't easy to answer so I'm just looking to see if someone can point me in the right direction to look at just now. am total newbie to programming, apart from knowing SQL, the thing is i have been given a MYSQL database containing various information about kids diseases and a web interface written in php to create reports from the database that can be accessed via the interface. there are almost 25 different variables that need to be computed in the report, i have written sql queries to compute all these values, but i don't know anything about PHP, if i have all these queries isn't there a way for me to combine all these sql queries to be display results on a webpage and come up with this report without writing PHP code? Thanks for your help very sorry if this is too basic hi I have 2 tables (members & friendship) Members table columns: -------------------------------------------- username | password | email | etc .... -------------------------------------------- Person 1 xxxxxx x@x.com person 2 yyyyyy y@y.com Friendship columns: --------------------------------------- username | friend | status | --------------------------------------- person 1 person 2 friends person 2 person 1 friends person 1 person 3 pending I want to query the friendship table: "SELECT friend FROM friendship WHERE username ='$_SESSION['myusername'];' AND status='friends' " (so its basically getting the user names of anyone who is the logged in users friend) And then use the returned user names to select their data from the members table. Any help much appreciated! ^.^ The whole code is below, followed by the part that isn't producing. It all works extremely well until the last part, and I have two instances of setting a variable to mysql_fetch_assoc that work. Not sure why the third attempt doesn't. I'm just trying to have a separate area that outputs 'msg'. Code: [Select] $sql = "SELECT * FROM players as p INNER JOIN schools as s WHERE p.tid = s.id ORDER BY status, playerLast"; $results = mysql_query($sql); echo '<div class="roster">'; $team = mysql_fetch_assoc($results); echo '<div class="team_info"> <div class="school">' . $team['school'] . '</div> <div class="coach">Coach ' .$team['coachFirst'] . ' ' . $team['coachLast'] .'</div> <div>Sectional: ' . $team['sectional'] . '</div> <div>Class: ' . $team['class'] . 'A</div> '; echo '</div>'; $currentStatus = false; //Flag to detect change in status while($player = mysql_fetch_assoc($results)) { if($currentStatus != $player['status']) { //Status has changed, display status header $currentStatus = $player['status']; echo '<br><b>'; if ($currentStatus == '1') {echo 'Returning Starters';} elseif ($currentStatus == '2') {echo 'Key Returners';} elseif ($currentStatus == '3') {echo 'Varsity Newcomers';} elseif ($currentStatus == '4') {echo 'Key Freshmen';} echo '</b><br>'; // echo "<div><b>{$currentStatus}</b></div>\n"; } //Display player info echo $player['playerFirst'] . ' ' . $player['playerLast'] . ', ' . $player['feet'] . '\'' . $player['inches'] . '",' . $player['position'] . ', ' . $player['year'] . ';<br>'; } //Player comments echo '<hr>'; echo '<div class="coach_comments"><span class="player_name">hello'; while($comments = mysql_fetch_assoc($results)) { echo $comments['playerFisrt'] . ' ' . $comments['playerLast'] . ': </span>' . $comments['msg']; } echo '</div>'; echo '</div>'; It's all working until what's below. All I get out of it is the "hello", which is just a test to make sure it wasn't a CSS issue. Quote //Player comments echo '<hr>'; echo '<div class="coach_comments"><span class="player_name">hello'; while($comments = mysql_fetch_assoc($results)) { echo $comments['playerFisrt'] . ' ' . $comments['playerLast'] . ': </span>' . $comments['msg']; } echo '</div>'; echo '</div>'; Hi everyone I have the following PHP code $sql.= "INSERT INTO `data` (`info`, `write`, `date`) VALUES"; $sql.= "("; for ($c=0; $c < $num; $c++) { $sql.= '"'.str_replace('"', "", $data[$c]).'",'; } $sql.= "'".date('Y-m-d')."');"; If I print $sql; I get Code: [Select] INSERT INTO `data` (`info`, `write`, `date`) VALUES("data99","n",'2010-10-05'); INSERT INTO `data` (`info`, `write`, `date`) VALUES("data101","y",'2010-10-05'); INSERT INTO `data` (`info`, `write`, `date`) VALUES("data876","n",'2010-10-05'); what would I need to do to my PHP code in order for it to process each QUERY either all at once or one at a time Whatever I try, it either inserts nothing, or just does the first INSERT Any ideas? Thanks I am using two seperate queries to calculate a streak, but the queries must be grouped together to find the actual streak? Query 1: SELECT COUNT(matchID) as streak, clan1 FROM webs_cup_matches WHERE ladID='17' AND clan1='2630' AND score1 > score2 AND confirmscore='1' AND einspruch='0' GROUP BY clan1 ORDER BY streak DESC LIMIT 1 Query 2: SELECT COUNT(matchID) as streak, clan2 FROM webs_cup_matches WHERE ladID='17' AND clan2='2630' AND score1 < score2 AND confirmscore='1' AND einspruch='0' GROUP BY clan2 ORDER BY streak DESC LIMIT 1 is it possible someone can join these queries together? Hi all, I would like to perform two queries in a mysqli statement before closing the connection. I'm using prepared statements and I've read on the php.net you can perform a multi-query using mysqli->multi_query. My problem is that I'm only finding useful examples on how to select and fetch results not using prepared statements. I'm a bit lost with how to do this to update two tables. Currently i'm using two seperate connections to do the queries but want to combine these together: Query one (updates their password and resets number of logins to force password change on next login): Code: [Select] //reset logins to force the user to change password upon next login $loggedin = '0'; // connect to db for mysqli require('../db/db.php'); // updates password and number of logins $insert_stmt = $mysqli->stmt_init(); if ($insert_stmt->prepare("UPDATE users SET their_password=?, loggedin=? WHERE their_username=?")) { $insert_stmt->bind_param('sss', $their_password, $time, $user_email); $insert_stmt->execute(); $insert_stmt->close(); } // if query errors sends an email if ($mysqli->error) { try { throw new Exception("MySQL error $mysqli->error <br> Query:<br> $query", $mysqli->errno); } catch(Exception $e ) { $mess = "Error No: ".$e->getCode(). " - ". $e->getMessage() . "<br >"; $mess .= nl2br($e->getTraceAsString()); $contact_email = "webmaster@website.com"; $message_sub = "Mysqli Forgotten Password Query Error [UPASSWORD01]"; $hdrs = "From: " . $contact_email . "\r\n"; $hdrs .= "Reply-To: ". $contact_email . "\r\n"; $hdrs .= "MIME-Version: 1.0\r\n"; $hdrs .= "Content-Type: text/html; charset=UTF-8\r\n"; mail($contact_email, $message_sub, $mess, $hdrs); } header("refresh: 10; forgotpass.php"); die('ERROR: Unable to reset password. Please check you details and try again or report this error to us using our contact us form.<br><br>We will redirect you back to the forgotten password form in 10 seconds.'); exit(); } $mysqli->close(); Query two (updates a reset log - to keep track on our user password resets): Code: [Select] // change status $resetstatus = "Successful Reset"; // connect to db for mysqli require('../db/db.php'); // inserts a new record $null = NULL; $insert_stmt = $mysqli->stmt_init(); if ($insert_stmt->prepare("INSERT INTO passwordresets VALUES (?, ?, ?, ?, ?)")) { $insert_stmt->bind_param('issss', $null, $user_email, $time, $userip, $resetstatus); $insert_stmt->execute(); $insert_stmt->close(); } // if query errors sends an email if ($mysqli->error) { try { throw new Exception("MySQL error $mysqli->error <br> Query:<br> $query", $mysqli->errno); } catch(Exception $e ) { $mess = "Error No: ".$e->getCode(). " - ". $e->getMessage() . "<br >"; $mess .= nl2br($e->getTraceAsString()); $contact_email = "webmaster@website.com"; $message_sub = "Mysqli Forgotten Password Query Error [UARESETLOG01]"; $hdrs = "From: " . $contact_email . "\r\n"; $hdrs .= "Reply-To: ". $contact_email . "\r\n"; $hdrs .= "MIME-Version: 1.0\r\n"; $hdrs .= "Content-Type: text/html; charset=UTF-8\r\n"; mail($contact_email, $message_sub, $mess, $hdrs); } header("refresh: 10; forgotpass.php"); die('ERROR: Unable to reset password. Please check you details and try again or report this error to us using our contact us form.<br><br>We will redirect you back to the forgotten password form in 10 seconds.'); exit(); } $mysqli->close(); Any ideas would be greatly appreciated. Thank you Not sure where to begin describing ths one?! On my website I have Articles. Beneath each Article, Users can leave one or more Comments. Next to each User's Comment, I have the following in the left margin... - Username - User Online Status - User Photo - User Location - User # of Posts At the top of my file, I have my PHP code and I start off by running a Prepared Statement looking for the Article the User is requesting in the URL. If the Article is found, I store the Results, and then run another Prepared Statement looking for Comments. If Comments are found, I store the Results. Then down in the HTML section, I display the Article and beneath it I loop through the Article's Comments like this... Code: [Select] // ******************************** // Display Comments on Article. * // ******************************** while (mysqli_stmt_fetch($stmt2)){ // Display User Info. * // Display User Comments. * } This seems to be working nicely, except that there is one last piece of User Info that is messing things up... I can get all of the User and Comments data in this query... Code: [Select] // ************************ // Build Comments Query. * // ************************ // Build query. $q2 = 'SELECT m.first_name, m.username, m.photo_name, m.photo_label, m.location, m.created_on, m.logged_in, m.last_activity, c.created_on, c.body, c.status FROM member AS m INNER JOIN comment AS c ON m.id = c.member_id WHERE c.status="Approved" AND c.article_id=? ORDER BY c.created_on'; However, in order to get the User's "Number of Posts" I need another query. And I'm not sure how to get the "Post Count" for each User and then mesh it back into what I currently have?! Does that make sense?! Also, it is conceivable that later I might add additional User Info that comes from yet another Query/Source. (If I was using OOP and PDO and had a clear separation of "Presentation" from "Business Logic" I'm sure would be easier, but for now I need to work with the structure I have since any of those three things are way beyond the scope of this question and my current abilities!!!!) Thanks, Debbie I'm working on a Stats page that will need to run multiple queries to access the information needed to dislpay on the page. Rather than running 30+ queries to get the user's Stats, is there a better method? Any tips that you suggest I further research? Thanks Hello all,
Based on the suggestion of you wonderful folks here, I went away for a few days (to learn about PDO and Prepared Statements) in order to replace the MySQLi commands in my code. That's gone pretty well thus far...with me having learnt and successfully replaced most of my "bad" code with elegant, SQL-Injection-proof code (or so I hope).
The one-and-only problem I'm having (for now at least) is that I'm having trouble understanding how to execute an UPDATE query within the resultset of a SELECT query (using PDO and prepared statements, of course).
Let me explain (my scenario), and since a picture speaks a thousand words I've also inlcuded a screenshot to show you guys my setup:
In my table I have two columns (which are essentially flags i.e. Y/N), one for "items alreay purchased" and the other for "items to be purchased later". The first flag, if/when set ON (Y) will highlight row(s) in red...and the second flag will highlight row(s) in blue (when set ON).
I initially had four buttons, two each for setting the flags/columns to "Y", and another two to reverse the columns/flags to "N". That was when I had my delete functionality as a separate operation on a separate tab/list item, and that was fine.
Now that I've realized I can include both operations (update and delete) on just the one tab, I've also figured it would be better to pare down those four buttons (into just two), and set them up as a toggle feature i.e. if the value is currently "Y" then the button will set it to "N", and vice versa.
So, looking at my attached picture, if a person selects (using the checkboxes) the first four rows and clicks the first button (labeled "Toggle selected items as Purchased/Not Purchased") then the following must happen:
1. The purchased_flag for rows # 2 and 4 must be switched OFF (set to N)...so they will no longer be highlighted in red.
2. The purchased_flag for row # 3 must be switched ON (set to Y)...so that row will now be highlighted in red.
3. Nothing must be done to rows # 1 and 5 since: a) row 5 was not selected/checked to begin with, and b) row # 1 has its purchase_later_flag set ON (to Y), so it must be skipped over.
Looking at my code below, I'm guessing (and here's where I need the help) that there's something wrong in the code within the section that says "/*** loop through the results/collection of checked items ***/". I've probably made it more complex than it should be, and that's due to the fact that I have no idea what I'm doing (or rather, how I should be doing it), and this has driven me insane for the last 2 days...which prompted me to "throw in the towel" and seek the help of you very helpful and intellegent folks. BTW, I am a newbie at this, so if I could be provided the exact code, that would be most wonderful, and much highly appreciated.
Thanks to you folks, I'm feeling real good (with a great sense of achievement) after having come here and got the great advice to learn PDO and prepared statements.
Just this one nasty little hurdle is stopping me from getting to "end-of-job" on my very first WebApp. BTW, sorry about the long post...this is the best/only way I could clearly explaing my situation.
Cheers guys!
case "update-delete": if(isset($_POST['highlight-purchased'])) { // ****** Setup customized query to obtain only items that are checked ****** $sql = "SELECT * FROM shoplist WHERE"; for($i=0; $i < count($_POST['checkboxes']); $i++) { $sql=$sql . " idnumber=" . $_POST['checkboxes'][$i] . " or"; } $sql= rtrim($sql, "or"); $statement = $conn->prepare($sql); $statement->execute(); // *** fetch results for all checked items (1st query) *** // $result = $statement->fetchAll(); $statement->closeCursor(); // Setup query that will change the purchased flag to "N", if it's currently set to "Y" $sqlSetToN = "UPDATE shoplist SET purchased = 'N' WHERE purchased = 'Y'"; // Setup query that will change the purchased flag to "Y", if it's currently set to "N", "", or NULL $sqlSetToY = "UPDATE shoplist SET purchased = 'Y' WHERE purchased = 'N' OR purchased = '' OR purchased IS NULL"; $statementSetToN = $conn->prepare($sqlSetToN); $statementSetToY = $conn->prepare($sqlSetToY); /*** loop through the results/collection of checked items ***/ foreach($result as $row) { if ($row["purchased"] != "Y") { // *** fetch one row at a time pertaining to the 2nd query *** // $resultSetToY = $statementSetToY->fetch(); foreach($resultSetToY as $row) { $statementSetToY->execute(); } } else { // *** fetch one row at a time pertaining to the 2nd query *** // $resultSetToN = $statementSetToN->fetch(); foreach($resultSetToN as $row) { $statementSetToN->execute(); } } } break; }CRUD Queston.png 20.68KB 0 downloads Main script gets class information from a database and prints them so long as the class start date or end date is after today (actually includes today).
Main script calls "instructors.php". It queries another database based on the instructor name ($chef) and then prints the bio information for that instructor.
"instructors.php" works fine on it's own, when I add "$chef = "Chef Name" ("Chef Name" is in the Instructors database). When it's called from the main script, nothing shows up in that area - even though "Chef Name" is in the database. All of the other data is printed fine, just not anything from instructors.php. I verified that it's actually including the file, as I can add "echo "test";" to the top of instructors.php and it prints fine in the main script.
Any ideas of what I'm missing?
Main Script
<?php // Get required login info include "/path/to/login/info/file.php"; // Get required login info - changed for this post. $db = new mysqli('localhost', $username, $password, $database); // Connect to DB using required login info if($db->connect_errno > 0){ die('Unable to connect to database [' . $db->connect_error . ']'); } unset($username);// put these variables back to null unset($password);// put these variables back to null unset($database);// put these variables back to null //query db $sql = <<<SQL SELECT * FROM `ft_form_7` WHERE DATE(class_start_date) >= CURDATE() OR DATE(class_end_date) >= CURDATE() ORDER BY class_start_date ASC SQL; if(!$result = $db->query($sql)){ // if there is an error in running the query, show error message. die('There was an error running the query [' . $db->error . ']'); } while($row = $result->fetch_assoc()){ // Get start date information $start_date = $row['class_start_date']; // Get event_start_date for conversion and call it $start_date $start_date_formatted = date("l M d, Y", strtotime($start_date)); // Convert start_date $end_date = $row['class_end_date']; // Get event_end_date for conversion and call it $start_date $end_date_formatted = date("M d, Y", strtotime($end_date)); // Convert start_date // Get time information. $start_time = $row['class_start_time']; // Get event_start_time for conversion and call it $start_time $start_time_formatted = date("h:i A", strtotime($start_time)); // Convert start_time $end_time = $row['class_end_time']; // Get event_end_time for conversion and call it $end_time $end_time_formatted = date("h:i A", strtotime($end_time)); // Convert end_time // echo information... echo "<h2>" , $row['class_name'],"</h2>" ; // echo event name echo "<p><strong>",$start_date_formatted; // echo the start date if (empty($start_time)) { echo ''; } else { echo " (", $start_time; } // echo start time if (empty($end_date)) { echo ''; } else { echo " -","<br />", $end_date_formatted; } // echo end date if (empty($end_time)) { echo ')'; } else { echo " - ", $end_time, ")"; } // echo end time // if there is no start time, echo nothing. (otherwise it seems to echo 4pm). If it does contain a time, echo the time. echo "</strong><br />"; $chef = $row['Instructor']; global $chef; if ($chef != NULL) { require ('instructors.php'); } echo $row['class_description'], "<br />"; echo "<strong>" , $row['type'], " - Cost: $",$row['cost'] , " - #" , $row['course_number'] , "</strong><br />" , "</p>"; // echo class type and cost } $db->close(); $result->free(); ?>instructors.php <?php include "/path/to/login/info/file.php"; // Get required login info - changed for this post. $db_instructors = new mysqli('localhost', $username, $password, $database); // Connect to DB using required login info if($db_instructors->connect_errno > 0){ die('Unable to connect to database [' . $db_instructors->connect_error . ']'); } unset($username);// put these variables back to null unset($password);// put these variables back to null unset($database);// put these variables back to null //query db $sql_instructors = <<<SQL SELECT * FROM ft_form_8 WHERE chef_name = '$chef' SQL; if(!$result_instructors = $db_instructors->query($sql_instructors)) { // if there is an error in running the query, show error message. die('There was an error running the query [' . $db_instructors->error . ']'); } while($row_instructors = $result_instructors->fetch_assoc()) { $chef_full_name = $row_instructors['chef_name']; $chef_id = $row_instructors['submission_id']; $full_bio = $row_instructors['full_bio']; echo "<a href=\"#\" class=\"clickme\">" , $chef_full_name , "</a>"; echo "<div class=\"box\">"; echo $full_bio , "</div>"; } $db_instructors->close(); $result_instructors->free(); ?> I'm using paypal PDT, so when the user has made payment he gets directed back to my site, on that page it executes a special sql query. I noticed I can refresh the page to make duplicate sql queries. How can I avoid this?? What would be the correct way to close a mysql query? At current the second query below returns results from the 1st query AND the 2nd query The 3rd query returns results from the 1st, 2nd and 3rd query. etc etc. At the moment I get somthing returned along the lines of... QUERY 1 RESULTS Accommodation 1 Accommodation 2 Accommodation 3 QUERY 2 RESULTS Restaurant 1 Restaurant 2 Restaurant 3 Accommodation 1 Accommodation 2 Accommodation 3 QUERY 3 RESULTS Takeaways 1 Takeaways 2 Takeaways 3 Restaurant 1 Restaurant 2 Restaurant 3 Accommodation 1 Accommodation 2 Accommodation 3 Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <?php include($_SERVER['DOCUMENT_ROOT'].'/include/db.php'); ?> <title>Untitled Document</title> <style type="text/css"> <!-- --> </style> <link href="a.css" rel="stylesheet" type="text/css" /> </head><body> <div id="listhold"> <!------------------------------------------------------------------------------------------------------------------------------------------------------> <div class="list"><a href="Placestostay.html">Places To Stay</a><br /> <?php $title ="TITLE GOES HERE"; $query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Accommodation' AND confirmed ='Yes' ORDER BY name"); echo mysql_error(); while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; $i = -1; foreach($nt as $value) {$i++; $FileName = str_replace(' ','_',$nt[$i]) . ".php"; $FileUsed = str_replace('_',' ',$nt[$i]); echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".php?title=$title&subtype=$FileUsed'>" . $nt[$i] . "</a>" . "<br/>"; $FileHandle = fopen($FileName, 'w') or die("cant open file"); $pageContents = file_get_contents("header.php"); fwrite($FileHandle,"$pageContents");} fclose($FileHandle); ?> </div> <!------------------------------------------------------------------------------------------------------------------------------------------------------> <div class="list"><a href="Eatingout.html">Eating Out</a><br /> <?php $title ="TITLE GOES HERE"; $query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Restaurant' AND confirmed ='Yes' ORDER BY name"); echo mysql_error(); while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; $i = -1; foreach($nt as $value) {$i++; $FileName = str_replace(' ','_',$nt[$i]) . ".php"; $FileUsed = str_replace('_',' ',$nt[$i]); echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".php?title=$title&subtype=$FileUsed'>" . $nt[$i] . "</a>" . "<br/>"; $FileHandle = fopen($FileName, 'w') or die("cant open file"); $pageContents = file_get_contents("header.php"); fwrite($FileHandle,"$pageContents");} fclose($FileHandle); ?> </div> <!------------------------------------------------------------------------------------------------------------------------------------------------------> <div class="list"><a href="Eatingin.html">Eating In</a><br /> <?php $title ="TITLE GOES HERE"; $query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Takeaways' AND confirmed ='Yes' ORDER BY name"); echo mysql_error(); while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; $i = -1; foreach($nt as $value) {$i++; $FileName = str_replace(' ','_',$nt[$i]) . ".php"; $FileUsed = str_replace('_',' ',$nt[$i]); echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".php?title=$title&subtype=$FileUsed'>" . $nt[$i] . "</a>" . "<br/>"; $FileHandle = fopen($FileName, 'w') or die("cant open file"); $pageContents = file_get_contents("header.php"); fwrite($FileHandle,"$pageContents");} fclose($FileHandle); ?> </div> <!------------------------------------------------------------------------------SKILLED TRADES BELOW---------------------------------------------------> <div class="list"><a href="Skilledtrades.html">Skilled Trades</a><br/> <?php $title ="TITLE GOES HERE"; $query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Skilled Trades' AND confirmed ='Yes' ORDER BY name"); echo mysql_error(); while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; $i = -1; foreach($nt as $value) {$i++; $FileName = str_replace(' ','_',$nt[$i]) . ".php"; $FileUsed = str_replace('_',' ',$nt[$i]); echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".php?title=$title&subtype=$FileUsed'>" . $nt[$i] . "</a>" . "<br/>"; $FileHandle = fopen($FileName, 'w') or die("cant open file"); $pageContents = file_get_contents("header.php"); fwrite($FileHandle,"$pageContents");} fclose($FileHandle); ?> </div> This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=351561.0 quick question, I have this code that returns over 100 buttons: Code: [Select] <?php // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM products"); while($row = mysql_fetch_array($sql)){ $product = $row["product"]; $id =$row["id"]; $price =$row["price"]; ?> <div id="products"> <form action="" method="POST" name="myform<?php echo $id; ?>" class="myform<?php echo $id; ?>"> <input type="hidden" name="hiddenField" class="hiddenField" value="<?php echo $product; ?>" /> <input type="hidden" name="hiddenField2" class="hiddenField2" value="<?php echo $id; ?>" /> <input type="hidden" name="hiddenField1" class="hiddenField1" value="<?php echo $price; ?>" /> <input type="submit" name="submit" class="submit" value="<?php echo $product; ?>" style="background-color:lightgreen; height:50px; width:100px;"> </form> </div> <?php } ?> What I would like is for the buttons to form columns of nine. ie 9 buttons in a column then a new column form.... how do I do this? |