PHP - Insert Data Into 100 Million Rows Without 500 Error?
So when I execute this it'll go for about 130k rows then give a 500 error. Any ideas how to avoid this and get it to complete?
Code: [Select] $i=10000000; while($i<=99999999) { $public = $i; $value = rand(10000000, 99999999); mysql_query("INSERT INTO yummy_table (public, value) VALUES('$public', '$value' ) ") or die(mysql_error()); $i++; } echo "done"; Similar TutorialsHi, after banging my head against the wall for a while thinking this would be a simple task, I'm discovering that this is more complicated than I thought. Basically what I have is a link table linking together source_id and subject_id. For each subject there are multiple sources associated with each. I had created a basic listing of sources by subject... no problem. I now need a way of having a form to create an ordered list in a user-specified way. In other words, I can currently order by id or alphabetically (subject name lives on a different table), but I need the option of choosing the order in which they display. I added another row to this table called order_by. No problem again, and I can manage all of this in the database, however I want to create a basic form where I can view sources by subject and then enter a number that I can use for sorting. I started off looping through each of the entries and the database (with a where), and creating a foreach like so (with the subject_id being grabbed via GET from the URL on a previous script) Code: [Select] while($row = mysqli_fetch_array($rs)) { //update row order if (isset($_POST['submit'])) { //get variables, and assign order $subject_id = $_GET['subject_id']; $order_by = $_POST['order_by']; $source_id = $row['source_id']; //echo 'Order by entered as ' . $order_by . '<br />'; foreach ($_POST['order_by'] as $order_by) { $qorder = "UPDATE source_subject set order_by = '$order_by' WHERE source_id = '$source_id' AND subject_id = '$subject_id'"; mysqli_query($dbc, $qorder) or die ('could not insert order'); // echo $subject_id . ', ' . $order_by . ', ' . $source_id; // echo '<br />'; } } else { $subject_id = $_GET['subject_id']; $order_by = $row['order_by']; $source_id = $row['source_id']; } And have the line in the form like so: Code: [Select] echo '<input type="text" id="order_by" name="order_by[]" size="1" value="'. $order_by .'"/> (yes I know I didn't escape the input field... it's all stored in an htaccess protected directory; I will clean it up later once I get it to work) This, of course, results in every source_id getting the same "order_by" no matter what I put into each field. I'm thinking that I need to do some sort of foreach where I go through foreach source_id and have it update the "order_by" field for each one, but I must admit I'm not sure how to go about this (the flaws of being self-taught I suppose; I don't have anyone to go to on this). I'm hoping someone here can help? Thanks a ton in advance 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> Hi all, I am managing a social network and am creating a script to allow the admin to private message all users on the site. Even setting the max execution time to unlimited within the file does not allow us to insert all 40,000 rows into the 'message' table, it stops after several thousand rows. Our hosts tell us setting this globally is a bad idea/unstable. Does anyone have some advice on the best to do this? No email notifications need to be sent so it is purely allowing the script to run it's full course without stopping. I did consider a cron job but without emails doing in 'batches' seems a bit unecessary so I'm clearly missing something. ANy and all advice would be most welcome! Richard i have created my own code of custom shopping cart
i have viewcart.php working great, now when i want to insert the orders from viewcart.php with list of like 5 items, how can i insert 5 names of products into my database 1 row
example
names are
1. jean
2. mond
3. richard
4. gwen
list above is the results of my while loop, now i want to insert those names to my database column[order_productname] so that i can identity what products are paid by my clients.
i tried fetch_array but if i assign variable to fetch array result, it only shows 1 which is "jean"
i wish this is possible
dforth
Hi coders,
i have a js to add multiple input and its depend to a user how many input should he want to add. and my problem is, it work insert data in a first line of rows but the rest of rows are not save.
any idea, what should i add to make it work.
js
<script> $(document).ready(function(){ $('#add').click(function(){ var inp = $('#box'); var i = $('input').size() + 1; $('<div id="box' + i +'"><input type="text" id="name" class="name" name="code[]' + i +'" placeholder="Input '+i+'"/><img src="remove.png" width="32" height="32" border="0" align="top" class="add" id="remove" /> </div>').appendTo(inp); i++; }); $('body').on('click','#remove',function(){ $(this).parent('div').remove(); }); }); </script>html <div id="box"> <input name = "code[]" type="text" id="name" class="name" placeholder="Input 1"> <img src="add.png" width="32" height="32" border="0" align="top" class="add" id="add" /> </div>php $rf = $_POST['regform']; $b = $_POST['branch']; $d = $_POST['date']; $c = $_POST['code']; $u = $_POST['user']; for($i = 0; $i<count($c); $i++) { $a_query = mysql_query("INSERT INTO code_number(ts_number,branch_id,yy,code,username) VALUES('$rf','$b','$d','$c[$i]','$u')"); } return $a_query; The information is drawn in from a table into a form that the user will click submit and all the rows will be inputted into the table with their username association. With this form, its only inputting the last row and not all of them. You're help is much appreciated! Here is the form in the PHP area: while($row=mysql_fetch_array($get_items_sql)){ $name =$row['item']; $date = ($row['expiration_date']); $exp_date = date('M d Y', strtotime($row['expiration_date'])); $content .= ""; $content .="<table width=\"450\" border=\"0\"><tr><td width=\"200\"><span class=\"anotherfont\"><input name=\"item[]\" type=\"hidden\" value=\"$name\" id=\"item[]\">$name</span></td><td width=\"200\"><span class=\"greenfont\"><input name=\"expiration_date[]\" type=\"hidden\" value=\"$date\" id=\"expiration_date[]\">$exp_date</span><input name=\"username[]\" type=\"hidden\" value=\"$username\" id=\"username[]\"/> </td></tr><br /></table>"; $content .= "\n"; } $content .= "</ul>\n"; Then below is part of the HTML Form with $content referenced: <form action="add_select.php?source_id=<?php echo $coupon_source ?>" method="post" enctype="multipart/form-data" name="add_new" id="add_new"> <?php echo $content ?> <input name="SUBMIT" type="submit" value="submit" /></form><br /> Then here is the section from the "add_select.php" file from the form: include('connect.php'); foreach($_POST['item'] as $row=>$item) { $Item_name=$item; $expiration_date=$_POST['expiration_date'][$row]; $username=$_POST['username'][$row]; } foreach($_POST['item'] as $row=>$item) { $Item_name=mysql_real_escape_string($item); $expiration_date=mysql_real_escape_string($_POST['expiration_date'][$row]); $username=mysql_real_escape_string($_POST['username'][$row]); } $sql2="INSERT INTO place (item, expiration_date, username) VALUES ('$Item_name', '$expiration_date', '$username')"; if (!mysql_query($sql2)) { die('Error: ' . mysql_error()); }else { header("location:insert_complete.php"); }
Hi, I have an app that access a MySQL database via a php script. For some reason when it is an SQL INSERT it returns -11 but as I said the INSERTS executes successfully. The app requesting the service sends in sequence: char* txtSQL[]={"INSERT INTO activity (mac,jd,date,time,area,type,value) VALUES ('a9c4952de6b4',2458454,'2018-12-01','10:22','Area0002','h',130)", "INSERT INTO activity (mac,jd,date,time,area,type,value) VALUES ('a9c4952de6b4',2458454,'2018-12-01','10:22','Area0002','h',130)", "INSERT INTO activity (mac,jd,date,time,area,type,value) VALUES ('a9c4952de6b4',2458454,'2018-12-01','10:22','Area0002','h',130)", "INSERT INTO activity (mac,jd,date,time,area,type,value) VALUES ('a9c4952de6b4',2458454,'2018-12-01','10:22','Area0002','h',130)", "UPDATE activity set value=333 where value=130", "SELECT sum(value) from activity where mac='a9c4952de6b4'", "DELETE from activity WHERE value=333"}; I set a monitor to check what was being returned and got: query=INSERT INTO activity (mac,jd,date,time,area,type,value) VALUES ('a9c4952de6b4',2458454,'2018-12-01','10:22','Area0002','h',130) HttpResponse: - httpResponseCode: -11 query=INSERT INTO activity (mac,jd,date,time,area,type,value) VALUES ('a9c4952de6b4',2458454,'2018-12-01','10:22','Area0002','h',130) HttpResponse: - httpResponseCode: -11 query=INSERT INTO activity (mac,jd,date,time,area,type,value) VALUES ('a9c4952de6b4',2458454,'2018-12-01','10:22','Area0002','h',130) HttpResponse: - httpResponseCode: -11 query=INSERT INTO activity (mac,jd,date,time,area,type,value) VALUES ('a9c4952de6b4',2458454,'2018-12-01','10:22','Area0002','h',130) HttpResponse: - httpResponseCode: -11 query=UPDATE activity set value=333 where value=130 HttpResponse: 4 * httpResponseCode: 201 -------------------------------------->As can be seem the INSERTS above returned error but worked OK query=SELECT sum(value) from activity where mac='a9c4952de6b4' HttpResponse: 1379 * httpResponseCode: 200 query=DELETE from activity WHERE value=333 HttpResponse: 4 * httpResponseCode: 201 The PHP script do ing the job i s as be low : <?php include('connection.php'); //these are just in case setting headers forcing it to always expire header('Cache-Control: no-cache, must-revalidate'); error_log(print_r($_POST,TRUE)); if( isset($_POST['query']) && isset($_POST['key']) ){ //checks if the tag post is there and if its been a proper form post header('Content-type: application/x-www-form-urlencoded'); if($_POST['key']==$SQLKEY){ //validates the SQL key $query=urldecode($_POST['query']); if(get_magic_quotes_gpc()){ //check if the worthless pile of crap magic quotes is enabled and if it is, strip the slashes from the query $query=stripslashes($query); } $conn = new mysqli($DB_ADDRESS,$DB_USER,$DB_PASS,$DB_NAME); //connect if($conn->connect_error){ //checks connection header("HTTP/1.0 400 Bad Request"); echo "ERROR Database Connection Failed: " . $conn->connect_error, E_USER_ERROR; //reports a DB connection failure } else { $result=$conn->query($query); //runs the posted query if($result === false){ header("HTTP/1.0 400 Bad Request"); //sends back a bad request error echo "Wrong SQL: " . $query . " Error: " . $conn->error, E_USER_ERROR; //errors if the query is bad and spits the error back to the client } else { if (strlen(stristr($query,"SELECT"))>0) { //tests if it's a SELECT statement $csv = ''; // bug fix Undefined variable: csv while ($fieldinfo = $result->fetch_field()) { $csv .= $fieldinfo->name.","; } $csv = rtrim($csv, ",")."\n"; //******************************** echo $csv; //prints header row $csv = ''; $result->data_seek(0); while($row = $result->fetch_assoc()){ foreach ($row as $key => $value) { $csv .= $value.","; } $csv = rtrim($csv, ","); //."\n"; } echo $csv; //prints all data rows } else { header("HTTP/1.0 201 Rows"); echo $conn->affected_rows; //if the query is anything but a SELECT, it will return the number of affected rows (INSERT IS RETURNING -11) } } $conn->close(); //closes the DB } } else { header("HTTP/1.0 400 Bad Request"); echo "-Bad Request"; //reports if the secret key was bad } } else { header("HTTP/1.0 400 Bad Request"); echo "*Bad Request"; } ?>
Any help will be much appreciated. Paulo Borges Hello, is it possible to insert somehow information from textarea to mysql? For example i have 3 lines in text area: John Tacker is a bad guy Tom Tacker has a big nose Ted Tacker is the same person as John Tacker and i want to insert them in table's different rows Hi again all, Why does the foreach loop im doing, put the array values from collection, into seperate table rows rather than 1 row per whole array? <?php class registration{ public $fields = array("username", "email", "password"); public $data = array(); public $table = "users"; public $dateTime = ""; public $datePos = 0; public $dateEntryName = "date"; public $connection; function timeStamp(){ return($this->dateTime = date("Y-m-d H:i:s")); } function insertRow($collection){ //HERE foreach($this->fields as $row => $value){ mysql_query("INSERT INTO $this->table ($value) VALUES ('$collection[$row]')"); } mysql_close($this->connection->connectData); } function validateFields(){ $this->connection = new connection(); $this->connection->connect(); foreach($this->fields as $key => $value){ array_push($this->data, $_POST[$this->fields[$key]]); } $this->dateTime = $this->timeStamp(); array_unshift($this->data, $this->dateTime); array_unshift($this->fields, $this->dateEntryName); foreach($this->data as $value){ echo "$value"; } $this->insertRow($this->data); } } $registration = new registration(); $registration->validateFields(); ?> I end up with 3 rows row 1: username row 2: email row 3 : password rather than row 1:username email password. Dear All, I have attached here with a schema, of MySql DB format i am refering to for the topic i need help on. I want to know what is the best way to achieve this problem / task. I have a profile table, and a category table, and a table to map profiles to category. Which allows me to define/add into the category_profile_mapping table, profile ids against a category id. Each category can have anywhere between 2 to 1,00,000 profiles mapped to it. I have another table called sms_out. hence on the site, when i select a category and submit the form value with message, i want to know what is the best way to populate sms_out with MSISDN from the table "Profile" and the message from the form. The list of MSISDN will be based on the category id selected, hence the profile id's will be available in the category_profile_mapping table. I am bad at explaining the problem, however incase you folks need more info do let me know. i shall be glad to provide the same to .. all of you guys who are willing to help me PS: I am asking this question, cuz i want to knw the best solution to achieve this, when there is entries in millions to be done at one form submit. [attachment deleted by admin] Hi.. Sorry, if I need to repost my problem in while loop. cause until now I can't resolve my problem in saving all data from while loop. I have this code StockRequisition.php where FORM was displayed. <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); $sr_date =date('Y-m-d H:i:s'); $sql = "SELECT sr_number FROM stock_requisition ORDER BY sr_date DESC LIMIT 1"; $result = mysql_query($sql, $con); if (!$result) { echo 'failed'; die(); } $total = mysql_num_rows($result); if ($total <= 0) { $currentSRNum = 1; $currentYear = (int)(date('y')); $currentMonth = (int)(date('m')); $currentDay = (int)(date('d')); $currentSRYMD = substr($row['sr_number'], 0, 6); $currentYMD = date("ymd"); if ($currentYMD > $currentSRYMD) { $currentSRNum = 1; } else { $currentSRNum += 1; } } else { //------------------------------------------------------------------------------------------------------------------ // Stock Number iteration.... $row = mysql_fetch_assoc($result); $currentSRNum = (int)(substr($row['sr_number'],0,3)); $currentSRYear = (int)(substr($row['sr_number'],2,2)); $currentSRMonth = (int)(substr($row['sr_number'],0,2)); $currentSRNum = (int)(substr($row['sr_number'],6,4)); $currentYear = (int)(date('y')); $currentMonth = (int)(date('m')); $currentDay = (int)(date('d')); $currentSRYMD = substr($row['sr_number'], 0, 6); $currentYMD = date("ymd"); if ($currentYMD > $currentSRYMD) { $currentSRNum = 1; } else { $currentSRNum += 1; } } //------------------------------------------------------------------------------------------------------------------ $yearMonth = date('ymd'); $currentSR = $currentYMD . sprintf("%04d", $currentSRNum); ?> <html> <title>Stock Requisition</title> <head> <link rel="stylesheet" type="text/css" href="kanban.css"> <script type="text/javascript"> function save_sr(){ var sr_date = document.getElementById("sr_date").value; var sr_number = document.getElementById("sr_number").value; var Items1 = document.getElementById("Items1").value; var SubItems = document.getElementById("SubItems").value; var ItemCode = document.getElementById("ItemCode").value; var DemandedQty = document.getElementById("DemandedQty").value; var UoM = document.getElementById("UoM").value; var Class = document.getElementById("Class").value; var Description = document.getElementById("Description").value; var BINLocation = document.getElementById("BINLocation").value; var RequestedBy = document.getElementById("RequestedBy").value; var ApprovedBy = document.getElementById("ApprovedBy").value; var ReceivedBy = document.getElementById("ReceivedBy").value; var IssuedBy = document.getElementById("IssuedBy").value; document.stock_requisition.action="StockRequisitionSave.php?sr_date="+sr_date+"&sr_number="+sr_number+"&Items1="+Items1+ "&SubItems="+SubItems+"&ItemCode="+ItemCode+"&DemandedQty="+DemandedQty+"&UoM="+UoM+"&Class="+Class+"&Description="+ Description+"&BINLocation="+BINLocation+"&RequestedBy="+RequestedBy+"&ApprovedBy="+ApprovedBy+"&ReceivedBy="+ReceivedBy+ "&IssuedBy="+IssuedBy; document.stock_requisition.submit(); alert("Stock Requisition data save."); window.location = "StockRequisition.php"; } </script> </head> <body> <form name="stock_requisition" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div id="ddcolortabs"> <ul> <li> <a href="ParameterSettings.php" title="Parameter Settings"><span>Parameter Settings</span></a></li> <li style="margin-left: 1px"><a href="kanban_report.php" title="WIP Report"><span>Wip Report</span></a></li> <li><a href="fsn.php" title="Finished Stock Note"><span>WMS FG</span></a></li> <li id="current"><a href="StockRequisition.php" title="WMS RM"><span>WMS RM</span></a></li> </ul> </div> <div id="ddcolortabs1"> <ul> <li><a href="ReceivingMaterials.php" title="Receiving Materials"><span>Receiving Materials</span></a></li> <li><a href="Shelving.php" title="Shelving"><span>Shelving</span></a></li> <li id="current"><a href="StockRequisition.php" title="Stock Requisition"><span>Stock Requisition</span></a></li> </ul> </div> <div id="SR_date"> <label>Date :</label> <input type="text" name="sr_date" value="<?php echo $sr_date; ?>" size="16" readonly="readonly" style="border: none;"> </div> <div id="SR_number"> <label>SR# :</label> <input type="text" name="sr_number" value="<?php echo $currentSR; ?>" size="10" readonly="readonly" style="font-weight: bold; border: none;"> <br/> </div> <div> <table> <thead> <th>Items</th> <th>Sub Items</th> <th>Item Code</th> <th>Demanded Qty</th> <th>UoM</th> <th>Class</th> <th>Description</th> <th>BIN Location</th> </thead> <?php $sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items"; $res_bom = mysql_query($sql, $con); while($row = mysql_fetch_assoc($res_bom)){ $Items = $row['Items']; echo "<tr> <td style='border: none;font-weight: bold;'> <input type='name' value='$Items' name='Items' id='Items' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='5'></td> </tr>"; $sql = "SELECT Items, SubItems, ItemCode, UoM, Class, Description, BINLocation FROM bom_subitems WHERE Items = '$Items' ORDER BY Items"or die(mysql_error()); $res_sub = mysql_query($sql, $con); while($row_sub = mysql_fetch_assoc($res_sub)){ $Items1 = $row_sub['Items']; $SubItems = $row_sub['SubItems']; $ItemCode = $row_sub['ItemCode']; $UoM = $row_sub['UoM']; $Class = $row_sub['Class']; $Description = $row_sub['Description']; $BINLocation = $row_sub['BINLocation']; echo "<tr> <td style='border: none;'> <input type='hidden' value='$Items1' id='Items1' name='Items1'></td> <td style='border: none;'> <input type='text' name='SubItems' value='$SubItems' id='SubItems' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'> <input type='text' name='ItemCode' value='$ItemCode' id='ItemCode' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'><center><input type='text' name='DemandedQty' id='DemandedQty' value='' size='7'></center></td> <td style='border: none;' size='3'> <input type='text' name='UoM' value='$UoM' id='UoM' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='3'></td> <td style='border: none;'> <input type='text' name='Class' value='$Class' id='Class' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'> <input type='text' name='Description' value='$Description' id='Description' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'> <input type='text' name='BINLocation' value='$BINLocation' id='BINLocation' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> </tr>"; } } ?> </table> </div> <?php $RequestedBy = array('AAA', 'BBB', 'CCC', 'DDD'); $ApprovedBy = array('EEE', 'FFF', 'GGG', 'HHH'); $ReceivedBy = array('III', 'JJJ', 'KKK', 'LLL'); $IssuedBy = array('MMM', 'NNN', 'OOO', 'PPP'); ?> <div id='Requested_By'> <label>Requested By:</label> <select name="RequestedBy"> <option value="Select">Select</option> <option value="AAA" <?php if($_POST['RequestedBy'] == 'AAA') echo "selected='selected'"; ?>>AAA</option> <option value="BBB" <?php if($_POST['RequestedBy'] == 'BBB') echo "selected='selected'"; ?>>BBB</option> <option value="CCC" <?php if($_POST['RequestedBy'] == 'CCC') echo "selected='selected'"; ?>>CCC</option> <option value="DDD" <?php if($_POST['RequestedBy'] == 'DDD') echo "selected='selected'"; ?>>DDD</option> </select> </div> <div id='Approved_By'> <label>Approved By:</label> <select name="ApprovedBy"> <option name='Select'>Select</option> <option value="EEE" <?php if($_POST['ApprovedBy'] == 'EEE') echo "selected='selected'"; ?>>EEE</option> <option value="FFF" <?php if($_POST['ApprovedBy'] == 'FFF') echo "selected='selected'"; ?>>FFF</option> <option value="GGG" <?php if($_POST['ApprovedBy'] == 'GGG') echo "selected='selected'"; ?>>GGG</option> <option value="HHH" <?php if($_POST['ApprovedBy'] == 'HHH') echo "selected='selected'"; ?>>HHH</option> </select> </div> <div id='Received_By'> <label>Issued By:</label> <select name="IssuedBy"> <option name='Select'>Select</option> <option value="III" <?php if($_POST['ReceivedBy'] == 'III') echo "selected='selected'"; ?>>III</option> <option value="JJJ" <?php if($_POST['ReceivedBy'] == 'JJJ') echo "selected='selected'"; ?>>JJJ</option> <option value="KKK" <?php if($_POST['ReceivedBy'] == 'KKK') echo "selected='selected'"; ?>>KKK</option> <option value="LLL" <?php if($_POST['ReceivedBy'] == 'LLL') echo "selected='selected'"; ?>>LLL</option> </select> </div> <div id='Issued_By'> <label>Received By:</label> <select name="ReceivedBy"> <option name='Select'>Select</option> <option value="MMM" <?php if($_POST['IssuedBy'] == 'MMM') echo "selected='selected'"; ?>>MMM</option> <option value="NNN" <?php if($_POST['IssuedBy'] == 'NNN') echo "selected='selected'"; ?>>NNN</option> <option value="OOO" <?php if($_POST['IssuedBy'] == 'OOO') echo "selected='selected'"; ?>>OOO</option> <option value="PPP" <?php if($_POST['IssuedBy'] == 'PPP') echo "selected='selected'"; ?>>PPP</option> </select> </div> <div id="save_btn"> <input type="button" name="button" value="save" onClick="save_sr()"> </div> </form> </body> </html> and here is StockRequisitionSave.php code for saving data to database : <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); $sr_date = $_POST['sr_date']; $sr_number = $_POST['sr_number']; $Items1 = $_POST['Items1']; $SubItems = $_POST['SubItems']; $ItemCode = $_POST['ItemCode']; $DemandedQty = $_POST['DemandedQty']; $UoM = $_POST['UoM']; $Class = $_POST['Class']; $Description = $_POST['Description']; $BINLocation = $_POST['BINLocation']; $RequestedBy = $_POST['RequestedBy']; $ApprovedBy = $_POST['ApprovedBy']; $ReceivedBy = $_POST['ReceivedBy']; $IssuedBy = $_POST['IssuedBy']; $sql = "INSERT INTO stock_requisition (sr_date, sr_number, Items, SubItems, ItemCode, DemandedQty, UoM, Class, Description, BINLocation, RequestedBy, ApprovedBy, ReceivedBy, IssuedBy) VALUES ('$sr_date', '$sr_number', '$Items1', '$SubItems', '$ItemCode', '$DemandedQty', '$UoM', '$Class', '$Description', '$BINLocation', '$RequestedBy', '$ApprovedBy', '$ReceivedBy', '$IssuedBy') "; $result = mysql_query($sql, $con); ?> the problem is only the last data was save. I will attach my form. I hope somebody can help me.. I really don't know how can I save all data from form into my database. Thank you so much for your understanding and help. Hi Team, I have a php page where I have taken the same userid and linked in the next page and also used show/hide function. I am able to see that the userid is linking but when i submit the data is not getting insert and also no error Please help below is the Tower.php file. 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=iso-8859-1" /> <title>BHP2</title> <style type="text/css"> <!-- #Layer1 { position:absolute; width:1005px; height:578px; z-index:1; left: 157px; top: 1px; background-color: #993399; } #Layer2 { position:absolute; width:939px; height:114px; z-index:1; left: 35px; top: 35px; } #Layer3 { position:absolute; width:451px; height:169px; z-index:2; left: 270px; top: 296px; } #Layer4 { position:absolute; width:608px; height:68px; z-index:2; left: 273px; top: 10px; } #Layer5 { position:absolute; left:82px; top:188px; width:973px; height:52px; z-index:2; } #Layer6 { position:absolute; width:243px; height:106px; z-index:2; left: 68px; top: 43px; } .style1 { font-size: xx-large; font-style: italic; } .style2 {font-size: 52px} #Layer7 { position:absolute; width:824px; height:271px; z-index:2; left: 44px; top: 237px; } .style4 { font-size: xx-large; font-style: italic; font-weight: bold; color: #FF9933; } #Layer8 { position:absolute; width:800px; height:139px; z-index:2; left: 31px; top: 67px; } #Layer9 { position:absolute; width:610px; height:30px; z-index:2; left: 34px; top: 70px; } #Layer10 { position:absolute; width:611px; height:25px; z-index:2; left: 33px; top: 110px; } #Layer11 { position:absolute; width:614px; height:30px; z-index:2; left: 33px; top: 152px; } #Layer12 { position:absolute; width:615px; height:29px; z-index:2; left: 32px; top: 193px; } #Layer13 { position:absolute; width:187px; height:35px; z-index:2; left: 318px; top: 239px; } --> </style> </head> <body> <div id="Layer1"> <form id="form5" name="form5" method="link" action="Insert.php"> <div id="Layer2"> <div id="Layer6"><img src="AZimages/BHP-Billiton-logo.jpg" width="235" height="65" alt="BHP" /></div> <h1 align="center"> </h1> <div class="style1" id="Layer4"> <h1 align="center" class="style2">BHP DATA TRACKER </h1> </div> </div> <div id="Layer7"> <div align="center"><span class="style4">SELECT THE TOWER BELOW </span> <div id="Layer13"> <input type="hidden" name="empid" value="<?php echo $_GET['id']; ?>" size="20"> <input type="hidden" name="date" value="<?php echo date("Y-m-d H:i:s"); ?>" > <input type="submit" name="B1" value="Start !" /> </div> <div id="Layer12"> <div align="left"> <input name="rad1" type="radio" value="RF" id="rad1" /> <label >RF</label> </div> </div> <div id="Layer11"> <div align="left"> <input name="rad1" type="radio" value="ISAP" id="rad1" /> <label >ISAP</label> </div> </div> <div id="Layer10"> <div align="left"> <input name="rad1" type="radio" value="GSD" id="rad1" checked="checked" /> <label >GSD</label> </div> </div> <div id="Layer9"> <div align="left"> <input name="rad1" type="radio" id="rad1" value="CSD" /> <label>CSD</label> </p> </div> </div> <br /> </div> </div> </form> </div> </body> </html> Below is the insert.php <!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"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>BHP DATA SUMBIT</title> <?php include ("count.php"); ?> <?php if(isset($_GET['action'])) { $action = $_GET['action']; if ($action = 'yes') { include ("Connection.php"); $PName = $_POST['rad11']; $Date = date("Y-m-d H:i:s"); $empidno = $_POST['idd']; $qsdate = $_POST['testinput']; $cb1 = $_POST['chkbox1']; $cb2 = $_POST['chkbox2']; $cb3 = $_POST['chkbox3']; $cb4 = $_POST['chkbox4']; $cb5 = $_POST['chkbox5']; $Com = $_POST['textfield2']; $dd1 = $_POST['textfield']; $dd2 = $_POST['select']; $dd3 = $_POST['select2']; $dd4 = $_POST['textfield4']; $dd5 = $_POST['textfield3']; $dd6 = $_POST['select3']; $sev = $_POST['radio1']; $olddate = $_POST['odate']; $pname = $_POST['radiobutton']; $query="INSERT INTO bhp ticketinformation (`userid`, `processname`, `begindate`, `dateposted`, `CALL`, `EMAIL`, `NEW`, `EXISTING`, `Piroty`, `MTICKET`, `Services`, `group1`, `group2`, `Icall`, `Tcreatedtime`, `comment`) VALUES ( '$empidno' , '$pname' , '$olddate' , '$Date' , '$cb1' , '$cb2' , '$cb3' , '$cb4' , '$sev' , '$dd1' , '$dd2' , '$dd3' , '$dd4' , '$dd5' , '$dd6' , '$Com')"; mysql_query($query); Header('location:tower.php?id=' . $empidno); } } ?> <head> <style type="text/css"> <!-- #Layer1 { position:absolute; width:1023px; height:592px; z-index:1; left: 167px; top: 2px; background-color: #993399; } #Layer2 { position:absolute; width:939px; height:114px; z-index:1; left: 59px; top: 3px; } #Layer3 { position:absolute; width:451px; height:169px; z-index:2; left: 270px; top: 296px; } #Layer4 { position:absolute; width:608px; height:68px; z-index:2; left: 273px; top: 10px; } #Layer5 { position:absolute; left:82px; top:188px; width:973px; height:52px; z-index:2; } #Layer6 { position:absolute; width:238px; height:69px; z-index:2; left: 68px; top: 43px; } .style1 { font-size: xx-large; font-style: italic; } .style2 {font-size: 52px} #Layer7 { position:absolute; width:979px; height:209px; z-index:2; left: 32px; top: 181px; } #Layer8 { position:absolute; width:194px; height:36px; z-index:1; left: 25px; top: 15px; } #Layer9 { position:absolute; width:178px; height:37px; z-index:2; left: 249px; top: 13px; } #Layer10 { position:absolute; width:193px; height:34px; z-index:3; left: 443px; top: 13px; } #Layer11 { position:absolute; width:204px; height:32px; z-index:4; left: 670px; top: 15px; } #Layer12 { position:absolute; width:195px; height:40px; z-index:5; left: 28px; top: 73px; } #Layer13 { position:absolute; width:182px; height:38px; z-index:6; left: 250px; top: 76px; } #Layer14 { position:absolute; width:197px; height:36px; z-index:7; left: 446px; top: 77px; } #Layer15 { position:absolute; width:214px; height:35px; z-index:8; left: 670px; top: 77px; } #Layer16 { position:absolute; width:315px; height:45px; z-index:9; left: 16px; top: 144px; } #Layer17 { position:absolute; width:343px; height:43px; z-index:10; left: 339px; top: 145px; } #Layer18 { position:absolute; width:258px; height:48px; z-index:11; left: 708px; top: 146px; } #Layer19 { position:absolute; width:321px; height:60px; z-index:3; left: 59px; top: 419px; } #Layer20 { position:absolute; width:197px; height:41px; z-index:1; left: 27px; top: 6px; } #Layer21 { position:absolute; width:193px; height:36px; z-index:2; left: 249px; top: 7px; } #Layer22 { position:absolute; width:207px; height:38px; z-index:3; left: 453px; top: 7px; } #Layer23 { position:absolute; width:237px; height:36px; z-index:4; left: 677px; top: 9px; } #Layer24 { position:absolute; width:245px; height:45px; z-index:5; left: 399px; top: 2px; } #Layer25 { position:absolute; width:99px; height:31px; z-index:6; left: 288px; top: 121px; } #Layer26 { position:absolute; width:87px; height:29px; z-index:7; left: 439px; top: 123px; } --> </style> <script language="JavaScript" > function showInfo() { var elem = document.getElementById('verify'); if(document.testform.select3.value == "verify" || document.testform.select3.value == "verify1" ) { elem.style.display="inline"; } else { elem.style.display="none"; } } </script> <script language="JavaScript"> function validator() { if(document.testform.Checkbox1.checked == false && document.testform.Checkbox2.checked == false && document.testform.Checkbox3.checked == false && document.testform.Checkbox4.checked == false) { alert ('You did not choose any of the checkboxes!'); return false; } if (document.testform.textfield.value =="") { alert("Enter Max Ticket No"); return false; } if (document.testform.select.value == "" || document.testform.select.value == "SELECT SERVICE DROP DOWN") { alert ('Select the SELECT SERVICE DROP DOWN'); return false; } if (document.testform.select2.value == "" || document.testform.select2.value == "SELECT RG GROUP") { alert ('SELECT RG GROUP'); return false; } if (document.testform.select3.value == "" || document.testform.select3.value == "SELECT GROUPS") { alert ('SELECT GROUPS'); return false; } if (document.testform.textfield2.value =="") { alert("Comments Feild is Empty.If there are no Comment then type NA(Not Applicable)"); return false; } if (document.testform.Checkbox1.checked == false) document.getElementById("chkbox1").value = ""; else document.getElementById("chkbox1").value = "EMAIL"; if (document.testform.Checkbox2.checked == false) document.getElementById("chkbox2").value = ""; else document.getElementById("chkbox2").value = "NEW"; if (document.testform.Checkbox3.checked == false) document.getElementById("chkbox3").value = ""; else document.getElementById("chkbox3").value = "EXISTING"; if (document.testform.Checkbox4.checked == false) document.getElementById("chkbox4").value = ""; else document.getElementById("chkbox4").value = "CALL"; alert('Record has been posted in the portal'); } </script> </head> <body> <div id="Layer1"> <div id="Layer2"> <div id="Layer6"><img src="AZimages/BHP-Billiton-logo.jpg" width="235" height="67" alt="BHP" /></div> <h1 align="center"> </h1> <div class="style1" id="Layer4"> <h1 align="center" class="style2">BHP DATA TRACKER </h1> </div> </div> <div id="Layer7"> <form method="POST" action="Insert.php?action=yes&&id=<?php echo $_GET['empid']; ?>" name="testform" onSubmit="return validator();"> <div id="Layer8"> <input type="checkbox" id="Checkbox4" name="checkbox4" value="CALL" /> CALL</label> </div> <div id="Layer9"> <label> <input type="checkbox" id="Checkbox1" name="checkbox1" value="EMAIL" /> EMAIL</label> </div> <div id="Layer10"> <label> <input type="checkbox" id="Checkbox2" name="checkbox2" value="NEW" /> NEW</label> </div> <div id="Layer11"> <label> <input type="checkbox" id="Checkbox3" name="checkbox3" value="EXISTING" /> EXISTING</label> </div> <div id="Layer12"> <label> <input name="radio1" type="radio" id="radio1" value="P1" checked="checked" /> P1</label> </div> <div id="Layer13"> <label> <input name="radio1" type="radio" id="radio1" value="P2" /> P2</label> </div> <div id="Layer14"> <label> <input name="radio1" type="radio" id="radio1" value="P3" /> P3</label> </div> <div id="Layer15"> <label> <input name="radio1" type="radio" id="radio1" value="P4" /> P4</label> </div> <div id="Layer16"> <label>MAXIMUM TICKET <input type="text" name="textfield" /> </label> </div> <div id="Layer17"> <label>SERVICE DROP DOWN <select name="select" style="width: 162px; height: 23px"> <option>SELECT SERVICE DROP DOWN</option> <option>OTHER(FW)</option> <option>1 MESSAGE</option> <option>1 MOBILITY</option> <option>1 VOICE</option> <option>1 SAP</option> <option>1 PORTAL</option> <option>1 COLLAB</option> <option>1 GSAP</option> <option>1 SECURITY</option> <option>1 WAN</option> <option>S DOMAIN</option> <option>1 AUTH</option> <option>1 DOCM</option> <option>1 REMOTE</option> </select> </label> </div> <div id="Layer18"> <label>RG GROUP <select name="select2" style="width: 162px; height: 23px"> <option>SELECT RG GROUP</option> <option>I-AM-AU-AM-HWT</option> <option>I-EUS-IN-CSC-DSK-CSD</option> <option>I-EUS-IN-CSC-DSK-GSD</option> <option>I-EUS-GB-DCS-BHPVICFW</option> <option>I-ITS-AU-HW</option> <option>I-SRM-AU-IAM-LAMU</option> <option>I-ITS-AU-SW</option> <option>C-BHP-AU-CSC-LSD-NONBRG</option> <option>C-BHP-AU-ACN-AQM</option> </select> </label> </div> </div> <div id="Layer19"> <label>SELECT GROUPS <select name="select3" onchange="showInfo()" style="width: 162px; height: 23px"> <option value="none" >SELECT GROUPS</option> <option value="verify">TP</option> <option value="verify1">OA</option> <option>OC</option> <option>OTHERS</option> </select> </label> <div id="verify" style="display:none;"> <br/><br/> <label>INCOMING CALL/EMAIL TIME <input type="text" name="textfield4" /> </label> <br/><br/> <label>MAXIMO TICKET CREATED TIME <input type="text" name="textfield3" /> </label> </div> <div id="Layer24"> <label>COMMENTS <input type="text" name="textfield2" /> </label> </div> <div id="Layer26"> <input name="Reset" type="reset" id="Reset" value="Reset" /> </div> <div id="Layer25"> <input type="submit" name="Submit" value="Submit" /> <input type="hidden" name="chkbox1" id="chkbox1" /> <input type="hidden" name="chkbox2" id="chkbox2" /> <input type="hidden" name="chkbox3" id="chkbox3" /> <input type="hidden" name="chkbox4" id="chkbox4" /> <input type="hidden" name="chkbox5" id="chkbox5" /> <input type="hidden" name="rad11" id="rad11" value="<?php echo $_GET['rad1']; ?>" /> <input type="hidden" name="idd" id="idd" value="<?php echo $_GET['empid']; ?>" /> <input type="hidden" name="odate" id="odate" value="<?php echo $_GET['date']; ?>" /> </form> </div> </div> </div> </body> </html> THANKS IN ADVANCED Hello,
This is confusing me! - this code is finding 2 rows of data ($nrows is 2), but I'm only getting 1 row of data returned. On the second while loop I'm getting the following error message:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/website.com/test.php on line 26
$query ="SELECT * FROM Accounts WHERE (jaaLatitude = '' OR jaaLongitude = '')"; $result=mysql_query($query) or die ("Connection to database table failed." . mysql_error()); $nrows=mysql_num_rows($result); $i = 0; if ($nrows > 0) { while($record = mysql_fetch_array($result, MYSQL_BOTH)) { $jaaIndex = $record[jaaIndex]; $jaaEmail = $record[jaaEmail]; $jaaLocation = $record[jaaLocation]; $jaaLongitude = $record[jaaLongitude]; $jaaLatitude = $record[jaaLatitude]; echo "<br>test jaaEmail is $jaaEmail<br>"; $i = $i + 1; } }As I say the first while loop is working, so I don't see what can be wrong with the qurery (it's not failing). Thanks for your help, S Hi, I am trying to output my data call rows, alongside each other till two, then break and start a new row. and so on and so on. this is not really a example question, i think its more a request information question and example question. How would i go about $outputting the rows alongside each other? i have tried: $output_rows['MYDATA']='then in here i have had a complete table with all the css and styling and information entered'; //but i couldn't get it alongside each other on the html page? then i tried outputting the information and had the tables and css setup on the .html page, but that gave me duplicate entries alongside each other, as no i was entering data from the {MYDATA}.. Twice.. I am really stuck! if any one can assist Great. Hey guys, I got another one that i could use some help on. I have a input form that utilizes a javascript that adds additional rows to my table. here is a look at what i got. Code: [Select] <script type="text/javascript"> function insertRow() { var x = document.getElementById('results_table').insertRow(-1); var a = x.insertCell(0); var b = x.insertCell(1); var c = x.insertCell(2); var d = x.insertCell(3); var e = x.insertCell(4); a.innerHTML="<input type=\"text\" name=\"id\">"; b.innerHTML="<input type=\"text\" name=\"place\">"; c.innerHTML="<input type=\"text\" name=\"username\">"; d.innerHTML="<input type=\"text\" name=\"earnings\">"; e.innerHTML="<input type=\"button\" value=\"delete\" onClick=\"deleteRow(this)\">"; } function deleteRow(r) { var i=r.parentNode.parentNode.rowIndex; document.getElementById('results_table').deleteRow(i); } </script> this is my code stored in the header of my page. basically just a button to add a new row and a button in each row to delete rows if needed. here is a look at my html table, pretty basic... Code: [Select] <table id="results_table"> <th>Event ID</th><th>Place</th><th>Username</th><th>Earnings</th> <tr> <td><input type="text" name="id"></td><td><input type="text" name="place"></td><td><input type="text" name="username"></td><td><input type="text" name="earnings"></td><td><input type="button" value="delete" onClick="deleteRow(this)"</td> </tr> </table> Now what I am hoping to acheive is once i submit all of these rows to the database i will insert each of these rows into their own row in the database. is this doable? the structure of my database is: ResultID (Primary Key) Place Earnings UserID (Foreign Key) EventID (Foreign Key) now i think the biggest problem i'm having with submitting data to the database is that in the original HTML form I am typing in the actual username and not the userID. so when it comes to processing I need to do a switch of these two things before I run my query. Should something like this work? Code: [Select] $username = $_POST['username']; $userID = "SELECT userID FROM users WHERE username="$username"; $query = mysql_query($userID); also i've never tried to submit multiple entries at a time. maybe i have to create an array somehow in order to capture each rows data. any thoughts? as always thanks for the help. i'm trying to echo out the results from a query onto a page, but rather than having them echo out as rows in a table, i want them to be displayed in columns, i.e. first column would have the first 10 results and the second column would have the next to. Any ideas on how i could do this? at the moment i'm using this code to display my results $read=mysql_query("SELECT * FROM entry WHERE category_id=".$id." ORDER BY entry_title") or die("query failed".mysql_error()); $result=mysql_num_rows($read); for($j = 0; $j < $result; $j++) { $row = mysql_fetch_array($read); echo "<a href=article.php?id=".$row['entry_id']. ">".$row['entry_title']."</a><br />"; } but this just displays it as a list down the middle thanks Here is a link to the website I am designing. http://173.167.65.189/singleton/ the username and password is ksingleton at the bottom where the calendar is the query is searching for scheduled events, i am only posting the company_id right now, the problem I am having is I want a scheduled event that continues through the week to stay in line with the one before. But if the schedule before ended and a new one continues it moves the next date company_id up. How can i align the table rows or create an empty table row on all other days if there was a schedule before. here is the code for the calendar. Quote <?php $db = new mysqli(); $setdate=strtotime($_GET['date']); $session=$_GET['session']; $calview=$_GET['calview']; if ($setdate <> "") { $date=$setdate; } else { $date=time(); } $day=date('d',$date); $month=date('m',$date); $year=date('Y',$date); $first_day=mktime(0,0,0,$month,1,$year); $title=date('F',$first_day); $day_of_week = date('D', $first_day); switch($day_of_week) { case "Sun": $blank = 0;break; case "Mon": $blank = 1;break; case "Tue": $blank = 2;break; case "Wed": $blank = 3;break; case "Thu": $blank = 4;break; case "Fri": $blank = 5;break; case "Sat": $blank = 6;break; } $days_in_month = cal_days_in_month(0, $month, $year); echo "<table cellpadding=0 cellspacing=0 border=0>"; echo "<tbody>"; echo "<tr>"; echo "<td><a href=?session=$session&calview=day>Day</a></td>"; echo "<td><a href=?session=$session&calview=week>Week</a></td>"; echo "<td><a href=?session=$session&calview=month>Month</a></td>"; echo "</tr>"; echo "<tr>"; echo "<td colspan=3>"; if ($calview=="month") { echo "<table border=1 width=800>"; echo "<tbody>"; echo "<tr height=25><th colspan=7> $title $year </th></tr>"; echo "<tr height=25><td width=58 align=center>Sunday</td><td width=58 align=center>Monday</td><td width=58 align=center>Tuesday</td><td width=58 align=center>Wednesday</td><td width=58 align=center>Thursday</td><td width=58 align=center>Friday</td><td width=58 align=center>Saturday</td></tr>"; $day_count = 1; echo "<tr height=50>"; while ( $blank > 0 ) { echo "<td></td>"; $blank = $blank-1; $day_count++; } $day_num = 1; while ($day_num <= $days_in_month ) { $newdate = $month ."/". $day_num ."/". $year; $msqlnewdate = date('m/d/Y',strtotime($newdate)); echo "<td valign=top><table cellpadding=0 cellspacing=0 border=0><tr><td><a href=?session=$session&calview=day&date=$newdate> $day_num </a></td></tr>"; $db = new mysqli('localhost','username','password', 'rsdata'); if (!$db) { echo 'ERROR: Could not connect to database.'; } else { $query = $db->query("SELECT * FROM rentals WHERE date_format(str_to_date(pdate_out,'%Y-%m-%d'), '%m/%d/%Y') <= '$msqlnewdate' AND date_format(str_to_date(pdate_in, '%Y-%m-%d'), '%m/%d/%Y') >= '$msqlnewdate'"); if ($query) { while ($result = $query->fetch_object()) { echo "<tr><td>".$result->company_id."</td></tr>"; } } echo "</table>"; } $day_num++; $day_count++; if ($day_count > 7) { echo "</tr><tr>"; $day_count=1; } } while ($day_count >1 && $day_count <=7 ) { echo "<td></td>"; $day_count++; } echo "</tr></table>"; } else if ($calview=="week") { } else { } echo "</td>"; echo "</tr>"; echo "</tbody>"; echo "</table>"; ?> MOD EDIT: DB credentials edited out. Hi, I'm having a bit of trouble with returning data from the database. It brings back the images etc... correctly, but I need to be able to limit it to two images per, line and then to carriage return. Or using CSS to position them with the correct padding etc... I'm very tired and can't seem to figure it out, which is starting to frustrate me. To see what I mean, go to www.bikescarsandvans.co.uk/test.php and select the drop down menu. And see coding for particular section. Any help will be much appericated, I know a good sleep would probaly help but don't have time for that right now Code: [Select] print " </td> <td colspan='2'> <div id='CollapsiblePanel" . $car_row["id"] . "' class='CollapsiblePanel'> <div class='CollapsiblePanelTab' tabindex='0'><img class='drop' src='images/drop_down.jpg' alt='Go' /></div> <div class='CollapsiblePanelContent'> <p> <div class='title_tabs'>Standard Specification</div> <table class='standard_spec'> <tr> <th> Engine Size: </th> <td> ".$car_row["engine"]." </td> </tr> <tr> <th> BHP: </th> <td> ".$car_row["bhp"]." </td> </tr> <tr> <th> Fuel Type: </th> <td> ".$car_row["fuel_type"]." </td> </tr> <tr> <th> Number of Doors: </th> <td> ".$car_row["no_doors"]." </td> </tr> <tr> <th> Wheels: </th> <td> ".$car_row["wheels"]." </td> </tr> </table> </p> "; //QUERY FOR TITLE START $query_title = "SELECT * FROM extras JOIN car_to_extra ON (car_to_extra.extras_id = extras.id) WHERE car_to_extra.car_id = '{$car_row['id']}' ORDER BY extras.price ASC"; $title_results = mysql_query($query_title) or die ("Error in query: $query_title. ".mysql_error()); $current_heading = ''; while ($title_row = @ mysql_fetch_array($title_results )) { if ($current_heading != $title_row["title"]) { // The heading has changed from before, so print the new heading here. $current_heading = $title_row["title"]; print " <p> <div class='title_tabs'>" . $title_row["title"] . "</div> "; } ?> <a class='data' href='#' onmouseout='hideTooltip()' onmouseover='showTooltip(event,"<?php print "" . $title_row["info"] . "<br/>(£" . $title_row["price"] . ")"; ?>");return false'> <?php print " <img class='extra_img' src=\"". $title_row["img"] ."\" alt='" . $title_row["img_alt"] . "' /></a> </p>"; } //QUERY FOR TITLE END print " </div> </div> <script type='text/javascript'> <!-- var CollapsiblePanel" . $car_row["id"] . " = new Spry.Widget.CollapsiblePanel('CollapsiblePanel" . $car_row["id"] . "', {contentIsOpen:false}); //--> </script> </td> </tr> "; Ok so I am pretty good with mysql and performing queries to get the data that I need. However, I have a question for any of you gurus out there that may be able to help me with an issue that I always run into with certain types of queries. Say I have 2 tables like this: Galleries id name 1 My Photos Gallery Photos id gallery_id photo 1 1 photo1.jpg 2 1 photo2.jpg 3 1 photo3.jpg Now usually when I pull this info from the database I have to do 2 separate queries in order to get the data and then link them so I would do something like. <?php //make the gallery query $query = "SELECT * FROM galleries"; $results = mysql_query($query); //setup an array for the galleries data $gallery_data = array(); //loop through the galleries for($i=0;$i<mysql_num_rows($results);$i++){ //add the gallery info to the gallery data array $gallery_data[$i] = mysql_fetch_array($results); //make the photos query with the gallery id $photo_query = "SELECT * FROM gallery_photos WHERE gallery_id='".mysql_real_escape_string($gallery_data[$i]['id'])."'"; $photo_results = mysql_query($photo_query); //setup the photos array $photo_data = array(); //put the photos in the array for($n=0;$n<mysql_num_rows($photo_results);$n++){ $photo_data[$n] = mysql_fetch_array($photo_results); } //add the photos to the gallery array $gallery_data[$i]['photos'] = $photo_data; } //now to display it is like this if(is_array($gallery_data)){ foreach($gallery_data as $gallery){ echo $gallery['name']; //show the photos if(is_array($gallery['photos'])){ foreach($gallery['photos'] as $photo){ echo $photo['photo']; } } } } ?> So my question is there a way to get all of this data at one time. I know how to do multiple queries in one and to do joins but they can only return one row as far as I know of. The only other way that I know how to do this is by ordering them by name and selecting them directly from the photos table and then just getting the gallery name like this: SELECT *,(SELECT name FROM galleries WHERE id=gallery_photos.id) AS gallery_name FROM gallery_photos ORDER BY gallery_id Then I could just do one loop and see if the name has changed and if so to output the new name. But I would like to know if there is a way to get a second set of results as an array from a query so I could just select the galleries and photos all in one query. Any help is appreciated. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=344772.0 |