PHP - Echo Multiple Rows In Multiple Columns
I want to echo out a few subcategories per main category.
It should be a maximum of 20 entries per column At this stage I have the following... It echo's the results out in 4 columns and not what I want. Any suggestions? $query = "SELECT adsubcat.name AS subname, adsubcat.linkname AS sublink, adcat.clinkname AS clink FROM adsubcat JOIN adcat ON adcat.id=adsubcat.catid WHERE adsubcat.catid='$catid' ORDER BY adsubcat.name ASC"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { $count = 0; print '<table style="text-align:left;margin-left:0px;width:943px;">'."\n"; while ($row = mysql_fetch_assoc($result)){ $gal = '<a href="'.$root.'/'.$row['clink'].'/'.$row['sublink'].'">'.$row['subname'].'</a>'; if ($count == 0){ print '<tr>'; } ++$count; print '<td>'.$gal.'</td>'; if ($count == 4){ $count = 0; print'</tr>'."\n"; } } print'</table>'."\n"; } Similar TutorialsThis topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=351561.0 Hi, I need help to check multiple rows for many columns, so that the script won't re-insert a duplicate entry. For eg: $isRowExist=mysql_query("SELECT (field1,field2) from table1 WHERE field1='$f1' AND field2='$f2' "); if(mysql_num_rows($isRowExist)==1) print "already in table1!"; else //proceed to insert into table table1 *BUT I tried this and it says mysql_num_rows expects resource, and this warning only shows when I have multipel columns I want to compare (it works just fine with one column in the WHERE clause above) Please help! Not sure if this is the right forum, but I have a database that I will need to populate with a large number of rows (2000+). I have written a PHP script that uploads individual entries. Is it possible to use something like a spreadsheet where I can set out the rows/columns as they will appear in the database, and then upload in one go rather than uploading each row individually? Thanks for any observations and/or help. Hi There, I have an SQL query that returns 10 rows, which I want to echo over 2 columns and 5 rows, however, I want rows 1-5 on the left hand column and rows 6-10 on the right hand side. Is there an easy way to do this? Normally I would do a fetch_array but, that would place the rows in order of, left, right, left, right - if that makes sense? Table is a standard table with 2 columns and 5 rows. Thanks Matt Hello all, I am trying to learn OOP in PHP so please forgive my ignorance. I seem to be having difficulty inserting data into my database from checkbox items. My database has a column for each each fruit. I would like for each column to be populated with either a one(1) for checked or a zero(0) for not checked. Currently, my attempts have failed. I can either get all checkboxes to insert all zeros or I can get the first column to insert a one(1) while the others as zeros. Is there anybody here that can help me figure out what I am doing wrong and help me to re-work my code so I can get this to work? If anybody can help me using OOP methods that would be fantastic. Thank you all in advance.
$preffruit->create_preffruit(array( 'fruit_apple' => escape(Input::get(['fruit_selection'][0]) ? 1 : 0), 'fruit_orange' => escape(Input::get(['fruit_selection'][1]) ? 1 : 0), 'fruit_banana' => escape(Input::get(['fruit_selection'][2]) ? 1 : 0), 'fruit_pear' => escape(Input::get(['fruit_selection'][3]) ? 1 : 0), 'fruit_kiwi' => escape(Input::get(['fruit_selection'][4]) ? 1 : 0) )); <input type="checkbox" name="fruit_selection[]" value="fruit_apple"> <input type="checkbox" name="fruit_selection[]" value="fruit_orange"> <input type="checkbox" name="fruit_selection[]" value="fruit_banana"> <input type="checkbox" name="fruit_selection[]" value="fruit_pear"> <input type="checkbox" name="fruit_selection[]" value="fruit_kiwi"> public function insert_preffruit($table, $fields = array()) { $keys = array_keys($fields); $values = ''; $x = 1; foreach($fields as $field) { $values .= '?'; if($x < count($fields)) { $values .= ', '; } $x++; } $sql = "INSERT INTO preffruit (`user_id`, `" . implode('`, `', $keys) . "`) VALUES (LAST_INSERT_ID(), {$values})"; if(!$this->query($sql, $fields)->error()) { return true; } return false; } Edited September 23, 2020 by ke-jo Ok I'm trying to insert multiple rows by using a while loop but having problems. At the same time, need to open a new mysql connection while running the insert query, close it then open the previous mysql connection. I managed to insert multiple queries before using a loop, but for this time, the loop does not work? I think it is because I am opening another connection... yh that would make sense actually? Here is the code: $users = safe_query("SELECT * FROM ".PREFIX."user"); while($dp=mysql_fetch_array($users)) { $username = $dp['username']; $nickname = $dp['nickname']; $pwd1 = $dp['password']; $mail = $dp['email']; $ip_add = $dp['ip']; $wsID = $dp['userID']; $registerdate = $dp['registerdate']; $birthday = $dp['birthday']; $avatar = $dp['avatar']; $icq = $dp['icq']; $hp = $dp['homepage']; echo $username." = 1 username only? :("; // ----- Forum Bridge user insert ----- $result = safe_query("SELECT * FROM `".PREFIX."forum`"); $ds=mysql_fetch_array($result); $forum_prefix = $ds['prefix']; define(PREFIX_FORUM, $forum_prefix); define(FORUMREG_DEBUG, 0); $con = mysql_connect($ds['host'], $ds['user'], $ds['password']) or system_error('ERROR: Can not connect to MySQL-Server'); $condb = mysql_select_db($ds['db'], $con) or system_error('ERROR: Can not connect to database "'.$ds['db'].'"'); include('../_phpbb_func.php'); $phpbbpass = phpbb_hash($pwd1); $phpbbmailhash = phpbb_email_hash($mail); $phpbbsalt = unique_id(); safe_query("INSERT INTO `".PREFIX_FORUM."users` (`username`, `username_clean`, `user_password`, `user_pass_convert`, `user_email`, `user_email_hash`, `group_id`, `user_type`, `user_regdate`, `user_passchg`, `user_lastvisit`, `user_lastmark`, `user_new`, `user_options`, `user_form_salt`, `user_ip`, `wsID`, `user_birthday`, `user_avatar`, `user_icq`, `user_website`) VALUES ('$username', '$username', '$phpbbpass', '0', '$mail', '$phpbbmailhash', '2', '0', '$registerdate', '$registerdate', '$registerdate', '$registerdate', '1', '230271', '$phpbbsalt', '$ip_add', '$wsID', '$birthday', '$avatar', '$icq', '$hp')"); if (FORUMREG_DEBUG == '1') { echo "<p><b>-- DEBUG -- : User added: ".mysql_affected_rows($con)."<br />"; echo "<br />-- DEBUG -- : Query used: ".end($_mysql_querys)."</b></p><br />"; $result = safe_query("SELECT user_id from ".PREFIX_FORUM."users WHERE username = '$username'"); $phpbbid = mysql_fetch_row($result); safe_query("INSERT INTO `".PREFIX_FORUM."user_group` (`group_id`, `user_id`, `group_leader`, `user_pending`) VALUES ('2', '$phpbbid[0]', '0', '0')"); safe_query("INSERT INTO `".PREFIX_FORUM."user_group` (`group_id`, `user_id`, `group_leader`, `user_pending`) VALUES ('7', '$phpbbid[0]', '0', '0')"); mysql_close($con); } include('../_mysql.php'); mysql_connect($host, $user, $pwd) or system_error('ERROR: Can not connect to MySQL-Server'); mysql_select_db($db) or system_error('ERROR: Can not connect to database "'.$db.'"'); } So I need to be able to insert these rows using the while loop.. how can I do this? I really appreciate any help. Hello all! I'm having some issues with a snippet that I found online and have edited to how I want it. Basically the code works at the moment, except if I were to search for 2 or 3 terms, it would search the columns username/action/result/changes for any result that have any of the words rather than results that include both terms, instead of either. I want the query to be like (assuming 2 search terms): Quote username LIKE '%$filter%' OR action LIKE '%$filter%' OR result LIKE '%$filter%' OR changes LIKE '%$filter%' AND username LIKE '%$filter%' OR action LIKE '%$filter%' OR result LIKE '%$filter%' OR changes LIKE '%$filter%' and not: Quote username LIKE '%$filter%' OR action LIKE '%$filter%' OR result LIKE '%$filter%' OR changes LIKE '%$filter%' OR username LIKE '%$filter%' OR action LIKE '%$filter%' OR result LIKE '%$filter%' OR changes LIKE '%$filter%' It needs an AND instead of an OR, but I'm not sure how to go around doing it. Here's the code as it is at the moment: $filter = ($_POST['filter']); $query = "SELECT * FROM activity WHERE"; $searchresult = explode(" ", $filter); foreach ($searchresult as $key => $filter) { $query .= " username LIKE '%$filter%' OR action LIKE '%$filter%' OR result LIKE '%$filter%' OR changes LIKE '%$filter%'"; if ($key != (sizeof($searchresult) - 1)) $query .= " AND "; } $query .= "ORDER BY id DESC"; Sorry if this is a little confusing to understand, hope someone understands what I need. Hi I'm trying to find the max value in 3 columns, new_date, reply_date and finalized_date in my table: Code: [Select] $test = safe_query("SELECT MAX(new_date) FROM (SELECT new_date AS new_date FROM ".PREFIX."cup_challenges UNION SELECT reply_date FROM ".PREFIX."cup_challenges UNION SELECT finalized_date FROM ".PREFIX."cup_challenges) AS maxval"); Did some research and have no idea what is wrong/if the above is correct? The page breaks below this code. Hi there, This is what I need to do, blow that is the code I have knocked up to do it but it doesn't seem to work. The main problem is the query that matches the atc callsigns to the pilots destinations.. can't fathom it myself. 1. Pull all the records from my database. 2. Assign their unique user id's, callsigns and destinations. 3. Execute a query in which you: SELECT * FROM CLIENTS WHERE (The 'clienttype' = 'ATC') AND match the callsign of the ATC users to the 'planned_destairport' of the 'clienttype' = 'PILOT'. For example if three people are going to Heathrow, then it would return 3 results. 4. Then do a mysql_num_rows of the result. 5. Lastly, execute a query that would update the 'atcarrivals' collumn in the database with the count number using the unique 'cid' as the identifier. All in a loop of course. // Selects all of the ATC Records. $atc_arrivals_selectquery = mysql_query ("SELECT * FROM CLIENTS"); // Starts the loop for fetching the records of the previous query. while($atc_arrivals_row = mysql_fetch_array($atc_arrivals_selectquery)){ // Sets the users cid, planned_destairport and callsign. $atc_cid = $atc_arrivals_row['cid']; $atc_destinations = $atc_arrivals_row['planned_destaiport']; $atc_callysign = $atc_arrivals_row['callsign']; // Searches the database and selects all records where the callsign is LIKE the destination airport. $atc_arrivals_check = mysql_query("SELECT * FROM CLIENTS WHERE clienttype = 'ATC' AND callsign LIKE '%$atc_destinations'"); // Counts previous query results. $atc_arrivals_count = mysql_num_rows($atc_arrivals_check); // Updates the atcarrivals column with the count.. $atc_arrivals_updatequery = mysql_query("UPDATE CLIENTS SET atcarrivals = '$atc_arrivals_count' WHERE cid = '$atc_cid' AND clienttype = 'ATC'"); // End loop. } Concerned columns are these: "cid" - Unique client id. "atcarrivals" - Number of arrivals from count. (This is the problem.) "planned_destairport" - Destination airport of pilot. Usually four letters long. IE. EGLL = Heathrow. Thanks. I'm wanting to output data into two columns. I've searched for this in a few places. A vast majority of the search results deal with getting data from multiple columns, and the the ones that deal with what I'm looking for don't really have any solutions attached to them. I'm not fully worried about the columns being equal length. The data is broken up into a certain number of rows in a given year. I have about 12 years, probably 6-8 rows per year. I just don't know how to get it into different columns. I don't care if it goes left to right then down or down then left to right. If there has been a solution to that here already, feel free to point me in that direction. Point me in any applicable direction, I'd fine with. I just can't locate anywhere what trigger would cause that. I have some code that selects one column from mysql table. However when I try to add more it doesn't work.
First the working code....
$query = "SELECT `profile_privacy` FROM `users` WHERE `user_username` = '$username'"; $result = mysql_query($query) or die($query."<br/><br/>".mysql_error()); $profile_privacy = mysql_result($result, 0);And here is where I have added another column.... $query = "SELECT `profile_privacy`, `profile_pictures` FROM `users` WHERE `user_username` = '$username'"; $result = mysql_query($query) or die($query."<br/><br/>".mysql_error()); $profile_privacy = mysql_result($result, 0); $profile_pictures = mysql_result($result, 1);What have I done wrong? Many thanks, I have this code which works fine. I want to improve it by displaying it into multiple columns. Current output: TITLE 1 JOB1 --------- TITLE 2 JOB 2 --------- ETC... I want it to display like this instead: TITLE 1 | TITLE 2 JOB 1 | JOB 2 Here is my code: $sql = "SELECT * FROM coaches WHERE position = 'Junior Coach'"; $result = mysql_query ($sql); while ($row = mysql_fetch_array($result)){ $id = $row["id"]; $firstname = $row["firstname"]; $lastname = $row["lastname"]; $position = $row["position"]; $image = $row["image"]; ?> <table width="183" border="1"> <tr> <td align="center" height="18"> <?php echo "<img id='image_shadowCoaches' src=" . $image . ">"; ?><br /> <?php echo "<div id='Coaches_Detail'>".$firstname." ".$lastname."</div>" ?> <?php echo "<div id='Coaches_DetailLower'>".$position."</div>" ?> </td> </tr> </table> <?php } ?> Hi All, Can't get this code working. the statement works fine directly on the table, just not when executed from the PHP file: Code: [Select] <strong>Multi Update</strong><br> <?php $host="localhost"; // Host name $username="user_name"; // Mysql username $password="Password"; // Mysql password $db_name="dbname"; // Database name $tbl_name="tablename"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT mik1vm_product.product_id, mik1vm_product.product_sku, mik1vm_product.product_name, mik1vm_product.product_in_stock, mik1vm_product.product_in_stock_cardiff FROM $tbl_name"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <table width="500" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <tr> <td> <table width="500" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"><strong>Product Id</strong></td> <td align="center"><strong>SKU</strong></td> <td align="center"><strong>Name</strong></td> <td align="center"><strong>In Stock</strong></td> <td align="center"><strong>In Stock Cardiff</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center"><? $product_id[]=$rows['product_id']; ?><? echo $rows['product_id']; ?></td> <td align="center"><input name="product_sku[]" type="text" id="product_sku" value="<? echo $rows['product_sku']; ?>"></td> <td align="center"><input name="product_name[]" type="text" id="product_name" value="<? echo $rows['product_name']; ?>"></td> <td align="center"><input name="product_in_stock[]" type="text" id="product_in_stock" value="<? echo $rows['product_in_stock']; ?>"></td> <td align="center"><input name="product_in_stock_cardiff[]" type="text" id="product_in_stock_cardiff" value="<? echo $rows['product_in_stock_cardiff']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </form> </table> <?php // Check if button name "Submit" is active, do this if($Submit){ for($i=0;$i<$count;$i++){ $sql1="UPDATE $tbl_name SET product_sku='$product_sku[$i]', product_name='$product_name[$i]', product_in_stock='$product_in_stock[$i]' , product_in_stock_cardiff='$product_in_stock_cardiff[$i]' WHERE product_id='$product_id[$i]'"; $result1=mysql_query($sql1); } } if($result1){ header("location:test.php"); } mysql_close(); ?> The page loads fine, but just doesn't update the DB. Thanks in advance for any help. I have ran this code before and it worked but not it won't update. Can anyone see what I am doing wrong? Code: [Select] <? if(isset($_POST[sort_invest])) { // if form was submitted $id = $_POST['sel_record']; $sort = $_POST['sort']; for($i=0;$i<$count;$i++){ $sql = "UPDATE invest SET id='$id[$i]', sort='$sort[$i]' WHERE id='$id[$i]'"; $sql_result = mysql_query($sql,$con) or die (mysql_error()); } } // if form was submitted or if it came from another page if (isset($_POST['order_invest']) || isset($_POST['sort_invest'])) { ?> <p><strong>Order Invest</strong></p> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <? $sql = "SELECT id, sort, title FROM invest ORDER BY sort ASC"; $sql_result = mysql_query($sql,$con) or die(mysql_error()); while ($row = mysql_fetch_array($sql_result)) { $id = $row["id"]; $title = $row["title"]; $sort = $row["sort"]; ?> <input type="hidden" name="sel_record[]" value="<? echo "$row[id]"; ?>"> <table width="545" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="69"><input type="text" name="sort[]" value="<? echo "$row[sort]"; ?>" size="3"></td> <td width="476"><? echo "$row[title]"; ?></td> </tr> </table> <br> <? } } ?> <input name="sort_invest" type="submit" value="Sort"> </form> The code below kind of works, I don't get any errors. It has 2 problems; it only inserts the second row of data I get nothing for the first row. It also does not insert the 4id correctly I just get 1 instead of the actually user id number. I'd appreciate some help, been trying to hack this out for a couple hours. Code: [Select] <?php // Begin the script for this page $id = $_SESSION['id']; if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form } else { //Assign each array to a variable $id = $_SESSION['id']; $store = $_POST['store']; $item = $_POST['item']; $itemprice = $_POST['itemprice']; $itemnumber = $_POST['itemnumber']; $couponvalue = $_POST['couponvalue']; $limit = count($id); for($i=0;$i<$limit;$i++){ $id[$i] = $id[$i]; $store[$i] = check_input($store[$i]); $item[$i] = check_input($item[$i]); $itemprice[$i] = check_input($itemprice[$i]); $itemnumber[$i] = check_input($itemnumber[$i]); $couponvalue[$i] = check_input($couponvalue[$i]); } $query = "INSERT INTO `item` (user_id, store, item, itemprice, itemnumber, couponvalue) VALUES ('".$id[$i]."','".$store[$i]."', '".$item[$i]."', '".$itemprice[$i]."', '".$itemnumber[$i]."', '".$couponvalue[$i]."')"; if (!mysql_query($query,$link)){ die('Error: ' . mysql_error()); } else { echo "$row record added"; } } ?> <div class="pageContent"> <div id="main"> <div class="container"> <form action="" method="post"> <table> <tr> <input type="text" name="id[]" id="id[]" value="<?php echo $_SESSION['id'];?>" /> <td><DIV CLASS="p2"><center><b>Store</b></center></div> <input type="text" name="store[]" id="store[]" size="15" maxlength="255"/></td> <td><DIV CLASS="p2"><center><b>Item</b></center></div> <input type="text" name="item[]" id="item[]" size="15" maxlength="255"/></td> <td><DIV CLASS="p2"><center><b>Item Price</b></center></div> <input type="text" name="itemprice[]" id="itemprice[]" size="15" maxlength="255"/></td> <td><DIV CLASS="p2"><center><b>Item Number</b></center></div> <input type="text" name="itemnumber[]" id="itemnumber[]" size="15" maxlength="255"/></td> <td><DIV CLASS="p2"><center><b>Coupon Value</b></center></div> <input type="text" name="couponvalue[]" id="couponvalue[]" size="15" maxlength="255"/></td> </tr> <tr> <input type="text" name="id[]" id="id[]" value="<?php echo $_SESSION['id'];?>" /> <td><input type="text" name="store[]" id="store[]" size="15" maxlength="255"/></td> <td><input type="text" name="item[]" id="item[]" size="15" maxlength="255"/></td> <td><input type="text" name="itemprice[]" id="itemprice[]" size="15" maxlength="255"/></td> <td><input type="text" name="itemnumber[]" id="itemnumber[]" size="15" maxlength="255"/></td> <td><input type="text" name="couponvalue[]" id="couponvalue[]" size="15" maxlength="255"/></td> </tr> </table> <input type="submit" name="submit" value="Submit Item"> </form> </div> </div> </div> I am running a query to get a certain student's quiz results from all attempts and print one after the other in a simple table for now. The student is designated by an email address. I need results from all of the rows containing this particular email. The issue I think I am having is that when I use "WHERE" and specify an email address that exists many times in the table it isn't storing the variable correctly. Here is code below that I cannot get working right. When I try to print these variables as a test to see if they are working I get nothing. No errors either. I have checked all names, spellings, and capitalization about 5 times. Thanks for looking at it. Code: [Select] $QuizQuery = mysql_query("SELECT * FROM Quiz_Results WHERE Email = '".$_SESSION['UserEmail']."' AND Quiz_Name = 'M1'") or die(mysql_error()); $i=1; while ($QuizResults = mysql_fetch_array($QuizQuery)){ $UserEmail = $QuizResults['Email']; $Score = $QuizResults['Score']; $Date = $QuizResults['Date_Taken']; echo "<table width='650' border='1'><tr><td>"; echo "Attempt #".$i."<br></td><td>Sco ".$Score."</td><td>"; if($QuizResults['Pass'] == "PASSED"){ echo "Passed"; } else { echo "Failed"; } echo "</td><td>Date Taken: ".$Date."</td></tr></table>"; $i++; } hey can someone advice me on how to make my update script update multiple rows. here's what i've got so far: update.php <?php require('connect.php'); $update = mysql_query("SELECT DISTINCT rideName FROM ride ORDER BY rideName DESC" ); $numrows = mysql_num_rows($update); echo "<form action='mysql_update.php' method='POST'> <select name='updateRide' >"; while ($row=mysql_fetch_assoc($update)) { #$rideID = $row ['rideID']; $rideName = $row ['rideName']; #$seatNumber = $row ['seatNumber']; #$time = $row ['time']; #$price = $row ['price']; echo "<option value='$id'> $rideName </option>"; } echo "</select> <input type='text' name='tochange'> <input type='submit' name='submit' value='change'> </form>"; ?> and now the handler script: mysql_update.php <?php require ('connect.php'); $updateRide=$_POST['updateRide']; $tochange=$_POST['tochange']; if ($updateRide&&$tochange) { $change = mysql_query("UPDATE ride SET rideName='$tochange' WHERE $id='updateRide'"); } ?> When I try this I get nothing, no changes. In the table there is 3 distinct rideNames each have more than 20 rows. Is there a way using the drop down box and ext field like i Have to update all of the distinct rideNames in the table? Thanks. Hey All, I tried seraching, but I'm not sure what exactly to search for. Here's what I need to do, and any push in the right direction would be great: I have a PHP form, with the Following: Text Box: Student ID Checkboxes for Activities What I need to do is somehow loop through and make a new row for each activity. Example, if I entered Student ID 105 and Activities are Basketball, Baseball, and Chess Team, I need three different rows in the database each listing the individual activity and the student ID. Any suggestions? I know how to do this if it was one entry (radio buttons) but want to be able to enter multiple rows at a time. Thanks! Code: [Select] - Generation Time: Aug 02, 2010 at 06:22 AM -- Server version: 5.0.91 -- PHP Version: 5.2.8 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -- -- Database: `leapaddemo` -- -- -------------------------------------------------------- -- -- Table structure for table `rp_user_occupants` -- CREATE TABLE `rp_user_occupants` ( `occupant_id` int(11) NOT NULL auto_increment, `occupant_name` varchar(100) NOT NULL, `occupant_dob` date NOT NULL, `occupant_relation` varchar(100) NOT NULL, `occupant_ssn` varchar(100) NOT NULL, `rp_user_id` int(11) NOT NULL, PRIMARY KEY (`occupant_id`), KEY `rp_user_occupants_ibfk_1` (`rp_user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=51 ; -- -- Dumping data for table `rp_user_occupants` -- INSERT INTO `rp_user_occupants` VALUES(1, 'sanju', '2010-06-04', 'myself', '123654', 1); INSERT INTO `rp_user_occupants` VALUES(2, 'jinson', '2010-07-07', 'frnd', '234245', 2); INSERT INTO `rp_user_occupants` VALUES(3, 'james', '2010-07-16', 'frnd', '234245', 2); INSERT INTO `rp_user_occupants` VALUES(4, 'sanju', '2010-07-30', 'friend', '789', 55); INSERT INTO `rp_user_occupants` VALUES(5, 'james', '2010-07-30', 'friend', '852', 55); INSERT INTO `rp_user_occupants` VALUES(6, 'james', '2010-07-09', 'friend', '789', 56); INSERT INTO `rp_user_occupants` VALUES(7, 'syam', '2010-07-16', 'friend', '852', 56); INSERT INTO `rp_user_occupants` VALUES(8, 'jinson', '2010-07-16', 'friend', '456', 56); INSERT INTO `rp_user_occupants` VALUES(9, 'james', '2010-07-02', 'friend', '789', 58); INSERT INTO `rp_user_occupants` VALUES(10, 'syam', '2010-07-10', 'friend', '852', 58); INSERT INTO `rp_user_occupants` VALUES(11, 'asdas', '2010-07-29', 'asdas', '', 60); INSERT INTO `rp_user_occupants` VALUES(12, 'sdfgd', '2010-07-30', 'sdfgdf', '', 60); INSERT INTO `rp_user_occupants` VALUES(13, 'syam', '2010-07-28', 'friend', '111111111', 61); INSERT INTO `rp_user_occupants` VALUES(14, 'james', '2010-07-28', 'friend', '222222222', 61); INSERT INTO `rp_user_occupants` VALUES(15, 'jinson', '2010-07-15', 'friend', '333333333', 61); INSERT INTO `rp_user_occupants` VALUES(16, 'james', '2010-07-28', 'friend', '111111111', 62); INSERT INTO `rp_user_occupants` VALUES(17, 'syam', '2010-07-29', 'friend', '222222222', 62); INSERT INTO `rp_user_occupants` VALUES(18, 'jinson', '2010-07-29', 'friend', '333333333', 62); INSERT INTO `rp_user_occupants` VALUES(19, 'siva', '1977-07-07', 'wewee', '111111111', 59); INSERT INTO `rp_user_occupants` VALUES(20, 'ASIT', '2002-07-11', 'FRIEND', '619072345', 63); INSERT INTO `rp_user_occupants` VALUES(21, 'Arati', '2010-07-17', 'Married', '619052731', 63); INSERT INTO `rp_user_occupants` VALUES(22, 'aaaaaa', '2010-07-29', 'aaaaaaaa', '111111111', 64); INSERT INTO `rp_user_occupants` VALUES(23, 'aaaaa', '2010-07-14', 'aaaaaaaaaaaa', '111111111', 64); INSERT INTO `rp_user_occupants` VALUES(24, 'bbbbbbbbb', '2010-07-30', 'bbbbbbbbbbb', '111111111', 64); INSERT INTO `rp_user_occupants` VALUES(25, 'werwerw', '2010-07-15', 'esdf', '23423232', 82); INSERT INTO `rp_user_occupants` VALUES(26, 'werwerw', '2010-07-15', 'esdf', '23423232', 82); INSERT INTO `rp_user_occupants` VALUES(27, 'james', '1986-04-22', 'friend', '3433434', 2); INSERT INTO `rp_user_occupants` VALUES(28, 'james', '2010-07-06', 'friend', '45645456', 2); INSERT INTO `rp_user_occupants` VALUES(29, 'syam', '2010-07-13', 'dfg', '545454', 2); INSERT INTO `rp_user_occupants` VALUES(30, 'jhhgj', '2010-07-13', 'hgj', '657677657', 2); INSERT INTO `rp_user_occupants` VALUES(31, 'syam', '2010-07-30', 'friend', '111111111', 88); INSERT INTO `rp_user_occupants` VALUES(32, 'james', '2010-07-30', 'friend', '111111111', 88); INSERT INTO `rp_user_occupants` VALUES(33, 'test occupant', '2000-07-21', 'test', '000', 89); INSERT INTO `rp_user_occupants` VALUES(34, 'test occupant', '2010-07-16', 'test relation', '000', 89); INSERT INTO `rp_user_occupants` VALUES(35, 'james', '2010-07-07', 'fff', '222222222', 2); INSERT INTO `rp_user_occupants` VALUES(36, 'james', '2010-07-01', 'fgdfg', '123456789', 2); INSERT INTO `rp_user_occupants` VALUES(37, 'werwerw', '2010-07-15', 'esdf', '23423232', 82); INSERT INTO `rp_user_occupants` VALUES(38, 'werwerw', '2010-07-15', 'esdf', '23423232', 82); INSERT INTO `rp_user_occupants` VALUES(39, 'werwerw', '2010-07-15', 'esdf', '23423232', 82); INSERT INTO `rp_user_occupants` VALUES(40, 'werwerw', '2010-07-15', 'esdf', '23423232', 82); INSERT INTO `rp_user_occupants` VALUES(41, 'werwerw', '2010-07-15', 'esdf', '23423232', 82); INSERT INTO `rp_user_occupants` VALUES(42, 'werwerw', '2010-07-15', 'esdf', '23423232', 82); INSERT INTO `rp_user_occupants` VALUES(43, 'dhoni', '2010-07-29', 'dhoni', '222222222', 90); INSERT INTO `rp_user_occupants` VALUES(44, 'dhoni', '2010-07-29', 'dhoni', '333333333', 90); INSERT INTO `rp_user_occupants` VALUES(45, 'ertertert', '2010-07-15', 'fff', '345453455', 82); INSERT INTO `rp_user_occupants` VALUES(46, 'dgfg', '2010-07-15', 'dfgdf', '444332222', 91); INSERT INTO `rp_user_occupants` VALUES(47, 'dhoni', '2010-07-28', 'frnd', '222222222', 92); INSERT INTO `rp_user_occupants` VALUES(48, 'dhoni', '2010-07-28', 'frnd', '222222222', 92); INSERT INTO `rp_user_occupants` VALUES(49, 'fdgdfg', '2010-08-06', 'fgdg', '233223', 91); INSERT INTO `rp_user_occupants` VALUES(50, 're', '2010-07-31', 'errrre', '223422342', 91); I want to edit these fields based on 'rp_user_id' field. I have to show them and update them to database. How. Please help me. Hi,
How can I select multiple columns from two tables and run a search through multiple fields?
My tables a
t_persons (holds information about persons)
t_incidents (holds foreign keys from other tables including t_persons table)
What I want is to pull some columns from the two tables above and run a search with a LIKE criteria, something like below. The code originally worked well with only one table, but for two tables it generate errors:
$query = "SELECT p.PersonID ,p.ImagePath ,p.FamilyName ,p.FirstName ,p.OtherNames ,p.Gender ,p.CountryID ,i.IncidentDate ,i.KeywordID ,i.IncidentCountryID ,i.StatusID FROM t_incidents AS i LEFT JOIN t_persons AS p ON i.PersonID = p.PersonID WHERE FamilyName LIKE '%" . $likes . "%' AND FirstName LIKE '%" . $likes . "%' AND OtherNames LIKE '%" . $likes . "%' AND Gender LIKE '%" . $likes . "%' AND IncidentDate LIKE '%" . $likes . "%' AND KeywordID LIKE '%" . $likes . "%' AND IncidentCountryID LIKE '%" . $likes . "%' AND StatusID LIKE '%" . $likes . "%' ORDER BY PersonID DESC $pages->limit";Errors a Column 'IncidentDate' in where clause is ambiguous Column 'KeywordID' in where clause is ambiguous Column 'IncidentCountryID' in where clause is ambiguous Column 'StatusID' in where clause is ambiguousThese columns are foreign keys on t_incidents table. I have also attached the table relationship diagram if it helps. I will appreciate any better way to do this. Thanx. Joseph Attached Files Model - 3.png 76.6KB 0 downloads |