PHP - How To Print Data Into A Paper?
Hello I would like to know how to print data generated by PHP into a bond paper? is there a php function that i can use? Similar Tutorialshello i have a label printer that i am trying to print to. it prints, but because of ie7 margins, it isnt printing properly. if i go in and manually change the margins, it will print propper. i cannot save the margins small enough though, any thoughts? thanks Hi all, This has just been bugging me forever, I actually just hardcoded the line it in years ago to just be done with it. But when I use the while loop to pull up the data for this table, it prints out every row but the last one. I've wracked my brain for years trying to fix it, and just cannot find the solution. Below is the entire page code I'm using and you can see at the bottom what I have sadly hardcoded in to make the last row display. That's the row that will not show up. If you want to see the actual live page it's he https://www.lakerstats.com/numerical-roster/ The UNK line at the end if the one that never prints out that I hardcoded. Page code as mentioned above. Appreciate any help! [php] $db = mysql_connect("localhost", "xxxx", "xxxx"); mysql_select_db("lakerstats",$db); echo "<table class=numeric WIDTH=100% cellpadding=0 cellspacing=0 border=0> <tr><td class=left colspan=\"2\" height=10><font size=\"2\" color=#000000>Current players are listed in ALL CAPS.<br />Retired uniforms are listed in <b><font color=\"#FF0000\">red</font></b>.<br /></font></td></tr><tr>"; $uniforms = "SELECT p.fname, p.lname, p.playerid, u.number, p.current_roster, u.retired, u.retired_player, p.profile_name, p.uniform_1, p.uniform_2 FROM player p, uniforms u WHERE u.number = p.uniform_1 or u.number = p.uniform_2 or u.number = p.uniform_3 or u.number = p.uniform_4 ORDER BY u.number+0, p.years, p.lname, p.fname"; $uniresult = mysql_query($uniforms) or die ("Query failed"); $numofrows = mysql_num_rows($uniresult); //let's get the number of rows in our result so we can use it in a for loop $temp = "0"; $sHTMLTemp = ""; while ($unirow = mysql_fetch_array($uniresult)) // Where $result is your result set { if ($temp != $unirow['number']) { $temp = $unirow['number']; if ($unirow['number'] == "100") { $unirow['number'] = "0"; } else if ($unirow['number'] == "101") { $unirow['number'] = sprintf("%02d", 0); } else if ($unirow['number'] == "102") { $unirow['number'] = "UNK"; } else { $unirow['number'] = $unirow['number']; } $sHTMLTemp = preg_replace("/(.+),/","\\1",$sHTMLTemp); print $sHTMLTemp ; print "</tr>"; $sHTMLTemp = ""; if ($unirow[retired] == "yes") { echo "<tr><td class=left height=10><font size=\"2\" color=\"#FF0000\"><b>#" . $unirow[number] . "</b></font><font size=\"2\"> - "; } else { echo "<tr><td class=left height=10><font size=\"2\" color=\"#000000\">#" . $unirow[number] . "</font><font size=\"2\"> - "; } } if ($unirow[current_roster] == "yes") { $unirow[fname] = strtoupper($unirow[fname]); $unirow[lname] = strtoupper($unirow[lname]); } else { $unirow[fname] = $unirow[fname]; $unirow[lname] = $unirow[lname]; } if ($unirow[retired_player] == $unirow[playerid]) { $sHTMLTemp .= "<b><a href=\"/player-stats-bio/?pname=".$unirow['profile_name']."\"><font color=\"#FF0000\">" . $unirow['fname'] . " " . $unirow['lname'] . "</font></a></b>, "; } else { $sHTMLTemp .= "<a href=\"/player-stats-bio/?pname=".$unirow['profile_name']."\">" . $unirow['fname'] . " " . $unirow['lname'] . "</a>, "; } } echo "<a href=\"/player-stats-bio/?pname=jim_fritsche\">Jim Fritsche</a>, <a href=\"/player-stats-bio/?pname=bobby_watson\">Bobby Watson</a>"; echo "</font></td></tr>"; echo "</font></td></tr></table>"; mysql_close($db); [/php] Edited September 14, 2020 by ban5150 so here the code that i am confusing the whole month , how can i get it to print out the filtered data
$sql="SELECT COUNT(*) as conflicts im so frustrated on myself that cant do anything Hi guys, I have a little problem here. I have stored the data in firstname column of mysql database. I am trying to achieve by print the data from the mysql and input the data on my php page, but the page is blank. Here it is the code: <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'myusername'); define('DB_PASSWORD', 'mypassword'); define('DB_DATABASE', 'mydatabasename'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $login = clean($_GET['user']); $password = clean($_GET['pass']); if($login == '') { $errmsg_arr[] = 'Login ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PASSWORD ID missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $qry="SELECT * FROM members WHERE login='$login' AND passwd='$password'"; $result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if(mysql_num_rows($result) > 0) { $row = mysql_fetch_row($result); $firstname = htmlspecialchars($author['firstname']); echo("$firstname <br>"); } else { echo 'Username and/or Password not found.'; } } ?> Do you know why the php page is blank as I effort to get the data from mysql?? Any idea?? so this is my code Code: [Select] <? $b=$_GET['b']; $m=$_GET['m']; $y=$_GET['y']; if ($b <> '' && $m <> '' && $y <> '') { $branch=$b; $leavemonth=$m; $leaveyear=$y; } else { $branch=$_POST['branch']; $leavemonth=$_POST['leavemonth']; $leaveyear=$_POST['leaveyear']; } $connection=mysql_connect("$server", "$username", "$password") or die("Could not establish connection"); mysql_select_db($database_name, $connection) or die ("Could not select database"); $query="SELECT * from tblworkgroup"; $result=mysql_query($query);?> Branch <select name="branch" > <option value="all">ALL Branches</option> <? while($row=mysql_fetch_array($result)) { ?> <option value= "<?=$row['WorkGroupID']?>" <? if ($branch==$row['WorkGroupID']){ echo 'selected'; } ?> ><?=$row['WorkGroupName']?></option> <? } ?> </select> </td> </tr> <br><br><br> Month <select name="leavemonth" > <option value = "1" <? if ($leavemonth==1){ echo 'selected'; } ?>>January</option> <option value = "2" <? if ($leavemonth==2){ echo 'selected'; } ?>>February</option> <option value = "3" <? if ($leavemonth==3){ echo 'selected'; } ?>>March</option> <option value = "4" <? if ($leavemonth==4){ echo 'selected'; } ?>>April</option> <option value = "5" <? if ($leavemonth==5){ echo 'selected'; } ?>>May</option> <option value = "6" <? if ($leavemonth==6){ echo 'selected'; } ?>>June</option> <option value = "7" <? if ($leavemonth==7){ echo 'selected'; } ?>>July</option> <option value = "8" <? if ($leavemonth==8){ echo 'selected'; } ?>>August</option> <option value = "9" <? if ($leavemonth==9){ echo 'selected'; } ?>>September</option> <option value = "10" <? if ($leavemonth==10){ echo 'selected'; } ?>>October</option> <option value = "11" <? if ($leavemonth==11){ echo 'selected'; } ?>>November</option> <option value = "12" <? if ($leavemonth==12){ echo 'selected'; } ?>>December</option> </select> Year <select name="leaveyear" > <option value = "2010" <? if ($leaveyear==2010) { echo 'selected';} ?>>2010</option> <option value = "2011" <? if ($leaveyear==2011) { echo 'selected';} ?>>2011</option> <option value = "2012" <? if ($leaveyear==2012) { echo 'selected';} ?>>2012</option> <option value = "2013" <? if ($leaveyear==2013) { echo 'selected';} ?>>2013</option> <option value = "2014" <? if ($leaveyear==2014) { echo 'selected';} ?>>2014</option> <option value = "2015" <? if ($leaveyear==2015) { echo 'selected';} ?>>2015</option> <option value = "2016" <? if ($leaveyear==2016) { echo 'selected';} ?>>2016</option> <option value = "2017" <? if ($leaveyear==2017) { echo 'selected';} ?>>2017</option> </select> <input type='submit' name='submit' value='Preview' Class="button" onclick='return validate()'> </div> </form> <br /><br /> <div id="box" valign="top"> <h3> <strong>Leave Application Details</strong>  </h3> <br><br> <FORM name="printbutton" method="post" align="left" action="report_print.php" target="_blank"> <input type="hidden" name="leavemonth" value="<?php echo $leavemonth; ?>"> <input type="hidden" name="leaveyear" value="<?php echo $leaveyear; ?>"> <input type="hidden" name="branch" value="<?php echo $branch;?>"> <Input type = "Submit" Name = "Submit1" Class="button" VALUE = "Print Leave Details"> </form> <table width="80%" align="center" > <thead> <tr> <th width="700px" align="left">Name</a></th> <th width="500px" align="center"></a>Application Date</th> <th width="500px" align="center"></a> </th> <th width="500x" align="right"></a>Reason</th> </tr> </thead> <tbody> <? /*echo "branch:".$branch.'<br />'; echo "leavemonth:".$leavemonth.'<br />'; echo "leaveyear:".$leaveyear.'<br />';*/ //-------------------------------------------------- if ($leavemonth =='' || $leaveyear =='' || $branch == '') { // one value missing, so don't display } else { // start display data $branchtracker = ''; if ($branch=='all'){ $branch = '%'; } $rs = mysql_query( " call vwleavereport('$leavemonth', '$leaveyear', $branch, 0);"); $query="SELECT *, MONTH(tblleaveapplication.DateFrom) as DFMonth, MONTH(tblleaveapplication.DateTo) as DTMonth, YEAR(tblleaveapplication.DateFrom) as DFYear FROM `tblleaveapplication` LEFT JOIN `tblemployee` ON tblleaveapplication.employeeid = tblemployee.id WHERE WorkGroupID LIKE '".$branch."' AND ( (MONTH(tblleaveapplication.DateFrom)=".$leavemonth." AND YEAR(tblleaveapplication.DateFrom)=".$leaveyear.") OR (MONTH(tblleaveapplication.DateTo)=".$leavemonth." AND YEAR(tblleaveapplication.DateFrom)=".$leaveyear.") ) ORDER BY WorkGroupID "; $result = mysql_query($query); while($row=mysql_fetch_array($result)) { if ($branchtracker<>$row['WorkGroupID']){ echo '<tr><td colspan=4 style="background-color: #e8e8e8; font-weight: bold;">'.$row['WorkGroupID'].'</td></tr>'; $branchtracker = $row['WorkGroupID']; } echo '<tr>'; echo '<td>'.$row['EmployeeName'].'</td>'; echo '<td>'.$row['DateFrom'].'</td>'; echo '<td>'.$row['DateTo'].'</td>'; echo '<td>'.$row['Purpose'].'</td>'; echo '</tr>'; } } ?> the problem is i want the print button only appear when there is output.. Hi guys, I have a problem of prints of the data from table1. I am checking out the data of username and password in the url to go through in members table and then checking the username in table1 to get matching data and select rows with the fields id of teststrings1, teststrings2 and teststrings3, then print out the data. Here it is the code <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'myusername'); define('DB_PASSWORD', 'password'); define('DB_DATABASE', 'mydatabasetable'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); if($username == '') { $errmsg_arr[] = 'username ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PASSWORD ID missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $qry="SELECT * FROM members WHERE username='$username' AND passwd='$password'"; $result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if($result) { $qrytable1="SELECT teststrings1, teststrings2, teststrings3 FROM table1 WHERE username='$username'"; $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); echo "<p id='teststrings1'>"; echo $row['teststrings1'] . "</p>"; echo "<p id='teststrings2'>"; echo $row['teststrings2'] . "</p>"; echo "<p id='teststrings3'>"; echo $row['teststrings3'] . "</p>"; } } ?> When I am am checking the data of username and password through in members table and then checking the username in table1 before select the rows with the fields id of teststrings1, teststrings2 and teststrings3 to prints out, but it have print out as blank on php page. Any idea? The following code returns thousands of results separated by a semicolon; Code: [Select] while($getpostid_result=mysql_fetch_array($getpostid)) { $postusername=$getpostid_result['username']; echo $postusername.";"; } the problem is it does not print everything in one row.it breaks into the nextline after if it encounters certain chatacters or some other reason. I want it to able to print everything in one row irrespective of the number of results returned. Hello, I am fairly new to PHP and I found some php code to print an array of numbers that create a combination - however, its slams all the numbers together without a space or a comma separator. How can I separate the numbers in this array with the given code? Ive attached a photo of the code.
I'm helping a friend in developing a project for our alma mater. And its based on this paper: An Enhanced Indoor Positioning Method Based on Wi-Fi RSS Fingerprinting So far 80% of the web app is finished except for the algorithm (We have no experience with algorithms to source code translations) that needs to be implemented in the website. Inside this paper there is this algorithm that the proponents of the research used. (attached as screenshot). The algorithm was converted to code by using MATLAB, but we are trying to use PHP with our project. Based on the pseudo code the calculation of the Euclidean Distance is the core of it. Can anyone help us with the translation just to get it started.
Hello.
i am totally new to php and just started to learn now. i just dont understand why the following code is not printing the username that i enter on the page.
Please note that the code itself is saved with the name "basicForm.php".
Thanks.
<html> Hello, How to customize print page in php ? I had a page, but I need to print it like an invoice look page. Thanks in advance Code: [Select] $query ="SELECT oneID FROM table WHERE table.PersonID = 'game.PlayerA'" ; $result = mysql_query($query); $row = mysql_fetch_array($result); $oneID = $row[0]; [code] If I then echo "$oneID" why does it not print anything? $result echos resource7 Am new here - looks like a great foru! I would sincerely appreciate any help anyone can give me. I have been trying to solve my problem for hours and I am not having any luck, so I thought I would post and see if anyone can help. I am very stuck and am not making much progress on this project, and I am certain the answer is very simple. I am constructing a form to collect data for a specialized purpose. The form and program actually work for its intended function, but I am trying to enhance the user experience by preventing customers from having to reenter all of their data should there be a problem with any of the data submitted. I have been able to do that with the contact form portion, but what I am having trouble with is the portion which has as many as 400 possible entries. So, in a nutshell, if the customers contact data is incomplete or in error, the form will ask them to return to the page and correct things. The previous data entered has been saved in the session and the input value will equal the previous entry. i.e. <tr> <td align="right" class="infoBox"><?php echo ENTRY_EMAIL_ADDRESS; ?></td> <td align=left><?php echo "<input type=text name='cemail' value=\"$cemail\" size=35 maxlength=35>" ?></td> </tr> Works perfectly, all well and good there. On the other 400 more or less entries, I am having a difficult time tweaking the string concatenation to work to achieve similar results. There are 4 columns each with $points entries asking for a dimension in either feet or inches. The <input name=> is one of ptaf,ptai,ptbf,ptbi, appended programatically with the corresponding row number or data point. i.e. "ptaf1", "ptai1", etc... This is produced by the example below and works perfectly also. <?php { $points=100; $i=1; while ($i <= $points) {echo ' <tr><td align="center" width="6"><b> ' .$i . '</b></td> <td align="right" NOWRAP>A' .$i . ' (ft) <input type="text" name="ptaf'.$i.'" size=4 maxlength=3> </td> <td align="right" NOWRAP>A' .$i . ' (in) <input type="text" name="ptai'.$i.'" size=4 maxlength=4> </td> <td align="right" NOWRAP>B' .$i . ' (ft) <input type="text" name="ptbf'.$i.'" size=4 maxlength=3> </td> <td align="right" NOWRAP>B' .$i . ' (in) <input type="text" name="ptbi'.$i.'" size=4 maxlength=4> </td> '; $i++; } } ?> I am trying to add <input value=$ptai.$i> for each field but as I mentioned I am not having any luck. It seems as if I have tried every combination imagineable, but still no luck. My head is spinning! The closest I seem to have gotten was with this: <td align="right" NOWRAP>A' .$i . ' (ft) <input type="text" size=6 maxlength=3 name="ptaf'.$i.'" value="' . "$ptaf" . $i . '" ></td> But line 17 for example returns this: <input type="text" value="17" name="ptaf17" maxlength="3" size="6"> To recap, I am trying to have the value set to whatever the customer may have entered previously. Again, I would most appreciate any help anyone can give me. If you need clarification on anything please let me know. Thanks AJ Hello to all, I have problem figuring out how to properly display data fetched from MySQL database in a HTML table. In the below example I am using two while loops, where the second one is nested inside first one, that check two different expressions fetching data from tables found in a MySQL database. The second expression compares the two tables IDs and after their match it displays the email of the account holder in each column in the HTML table. The main problem is that the 'email' row is displayed properly while its while expression is not nested and alone(meaning the other data is omitted or commented out), but either nested or neighbored to the first while loop, it is displayed horizontally and the other data ('validity', 'valid_from', 'valid_to') is not displayed.'
Can someone help me on this, I guess the problem lies in the while loop? <thead> <tr> <th data-column-id="id" data-type="numeric">ID</th> <th data-column-id="email">Subscriber's Email</th> <th data-column-id="validity">Validity</th> <th data-column-id="valid_from">Valid From</th> <th data-column-id="valid_to">Valid To</th> </tr> </thead> Here is part of the PHP code:
<?php while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo ' <tr> <td>'.$row["id"].'</td> '; while ($row1 = $stmt1->fetch(PDO::FETCH_ASSOC)) { echo ' <td>'.$row1["email"].'</td> '; } if($row["validity"] == 1) { echo '<td>'.$row["validity"].' month</td>'; }else{ echo '<td>'.$row["validity"].' months</td>'; } echo ' <td>'.$row["valid_from"].'</td> <td>'.$row["valid_to"].'</td> </tr>'; } ?>
Thank you. I have two tables. Table Name:Users Fields: User_name user_email user_level pwd 2.Reference Fields: refid username origin destination user_name in the users table and the username field in reference fields are common fields. There is user order form.whenever an user places an order, refid field in reference table will be updated.So the user will be provided with an refid Steps: 1.User needs to log in with a valid user id and pwd 2.Once logged in, there will be search, where the user will input the refid which has been provided to him during the time of order placement. 3.Now User is able to view all the details for any refid 3.Up to this we have completed. Query: Now we need to retrieve the details based on the user logged in. For eg: user 'USER A' has been provided with the referenceid '1234' during the time of order placement user 'USER B' has been provided with the referenceid '2468' during the time of order placement When the userA login and enter the refid as '2468' he should not get any details.He should get details only for the reference ids which is assigned to him. <?php session_start(); if (!$_SESSION["user_name"]) { // User not logged in, redirect to login page Header("Location: login.php"); } $con = mysql_connect('localhost','root',''); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("login", $con); $user_name = $_POST['user_name']; $refid = $_POST['refid']; $query = "SELECT * from reference,users WHERE reference.username=users.user_name AND reference.refid='$refid' AND "; $result = mysql_query($query) or trigger_error('MySQL encountered a problem<br />Error: ' . mysql_error() . '<br />Query: ' . $query); while($row = mysql_fetch_array($result)) { echo $row['refid']; echo $row['origin']; echo $row['dest']; echo $row['date']; echo $row['exdate']; echo $row['username']; } echo "<p><a href=\"logout.php\">Click here to logout!</a></p>"; ?> <html> <form method="post" action="final.php"> Ref Id:<input type="text" name="refid"> <input type="submit" value="submit" name="submit"> </html> Hi, 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 Here's the code that deals with the client side:
<?php session_start(); if(!isset($_SESSION['Logged_in'])){ header("Location: /page.php?page=login"); } ?> <!DOCTYPE Html> <html> <head> <!--Connections made and head included--> <?php require_once("../INC/head.php"); ?> <?php require_once("../Scripts/DB/connect.php"); ?> <!--Asynchronously Return User Names--> <script> $(document).ready(function(){ function search(){ var textboxvalue = $('input[name=search]').val(); $.ajax( { type: "GET", url: 'search.php', data: {Search: textboxvalue}, success: function(result) { $("#results").html(result); } }); }; </script> </head> <body> <div id="header-wrapper"> <?php include_once("../INC/nav2.php"); ?> </div> <div id="content"> <h1 style="color: red; text-align: center;">Member Directory</h1> <form onsubmit="search()"> <label for="search">Search for User:</label> <input type="text" size="70px" id="search" name="search"> </form> <a href="index.php?do=">Show All Users</a>|<a href="index.php?do=ONLINE">Show All Online Users</a> <div id="results"> <!--Results will be returned HERE!--> </div>search.php <?php //testing if data is sent ok echo "<h1>Hello</h1><br>" . $_GET['search']; ?>This is the link I get after sending foo. http://www.family-li...php?&search=foo Is that mean it was sent, but I'm not processing it correctly? I'm new to the whole AJAX thing. Say there is a complex opt in process where people start to enter their data but certain questions stop them where they close out of the page. They already entered their data and I feel there is a way to grab it and post it to mysql even though they do not click submit.
How would this be done?
A super simple example (proof of concept) or a link to a tutorial would be very useful.
Edited by brentman, 23 September 2014 - 10:42 AM. This could be PHP or MySql so putting it in PHP forum for now... I have code below (last code listed) which processes a dynamically created Form which could have anywhere from 0 to 6 fields. So I clean all fields whether they were posted or not and then I update the mySQL table. The problem with this code below is that if, say, $cextra was not posted (i.e. it wasnt on the dynamically created form), then this code would enter a blank into the table for $cextra (i.e. if there was already a value in the table for $cextra, it gets overwritten, which is bad). What is the best way to handle this? I'm thinking i have to break my SQL query into a bunch of if/else statements like this... Code: [Select] $sql = "UPDATE cluesanswers SET "; if (isset($_POST['ctext'])){ echo "ctext='$ctext',"; } else { //do nothing } and so on 5 more times.... That seems horribly hackish/inefficient. Is there a better way? Code: [Select] if (isset($_POST['hidden']) && $_POST['hidden'] == "edit") { $cimage=trim(mysql_prep($_POST['cimage'])); $ctext=trim(mysql_prep($_POST['ctext'])); $cextra=trim(mysql_prep($_POST['cextra'])); $atext=trim(mysql_prep($_POST['atext'])); $aextra=trim(mysql_prep($_POST['aextra'])); $aimage=trim(mysql_prep($_POST['aimage'])); //update the answer edits $sql = "UPDATE cluesanswers SET ctext='$ctext', cextra='$cextra', cimage='$cimage', atext='$atext', aextra='$aextra', aimage='$aimage'"; $result = mysql_query($sql, $connection); if (!$result) { die("Database query failed: " . mysql_error()); } else { } Im trying to print several image url's and names from an sql database into 3 columns, Aiming to get it to go 1,2,3 4,5,6 7,8,9 etc etc. but for some reason myne is going 1,3,5 2,4,6 etc. Dont bother mentioning that my loops do nothing, i realised that about 10 minutes ago, Any help would be appreciated. <?php include 'config.php'; mysql_connect($host, $user, $pass) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); $result = mysql_query("SELECT * FROM tracks"); echo '<div id="left_wrapper">'; for ($i=0;$i<mysql_num_rows($result);$i+=3) { $row = mysql_fetch_array($result); $id = $row['id'] + 1; echo "<img src='Thumbnails/" . $id .".gif'></img><br>"; echo $row['name']. "<br>"; } echo "</div>"; echo '<div id="middle_wrapper">'; for ($i=1;$i<mysql_num_rows($result);$i+=3) { $row = mysql_fetch_array($result); $id = $row['id'] + 1; echo "<img src='Thumbnails/" . $id .".gif'></img><br>"; echo $row['name']. "<br>"; } echo "</div>"; echo '<div id="right_wrapper">'; for ($i=2;$i<mysql_num_rows($result);$i+=3) { $row = mysql_fetch_array($result); $id = $row['id'] + 1; echo "<img src='Thumbnails/" . $id .".gif'></img><br>"; echo $row['name']. "<br>"; } echo "</div>"; ?> i know each of those loops does nothing, But you can see where they are meant to do, Each div is aligned to different positions, first loop is left, 2nd is center, 3rd is right. |