PHP - Echo An Image From Database
Hi,
I have a search results page that return the results based on "Make" & "Model" of vehicle. The question is, can an image be echoed onto that results page based on which make and model has been searched for? The image is stored in a field called "Image_Van" so would need to display that depending on the row in that database that has been selected from Make & Model... Hope this makes sense! <?php //info bars colour $color_info="#D6D685"; // Almost Silver //FFFFCC $color1="#E9E9E9";// Light Blue $color2="#EAD5FF";// Light Blue //include function library code include_once("func_lib.php"); // use the user_connection include file's connectDB function include_once("usr_conn.php"); if (!connectDB()) { echo "<p>Unable To Connect To Database</p>"; return; } //test that make and model are passed in, if they are assign them if (($_GET ['make'] == "MAKE") or ($_GET ['model'] == "MODEL")) { $errMessage = "<br><br><b><font class=small>Your search hasn't returned any results, please re-enter your search again.</font></b><br><br><a href=van_accessories.php>Search again</a><br><br>"; } else { // get search values for make and model, removing " and ' chars $strMake = mysql_escape_string($_GET ['make']); $strModel = mysql_escape_string($_GET ['model']); } // set the Prod_Type that is to be shown regardless of car make and model $strDefaultProd = "XD"; //write query string that will pased in paging links $strQuery = "make=".$strMake."&model=".$strModel."&"; //echo $strQuery; //grab the page number that we're on $page = mysql_escape_string($_GET ['page']); //$strMake = "FIAT"; //$strModel = "Uno"; //create sql query $sqlSelect = "SELECT Prod_ID, Prod_Type, Prod_Model, Prod_Make, Prod_REF, Product_Desc, Price_ExVat, image_name, Image_Van FROM products"; //change this back to 'FILL THIS IS IN' to switch accessories off! $criteria = " WHERE (Car_Make = '".$strMake."' AND Car_Model = '".$strModel."' AND Default_Code = 'RS') OR (Car_Make = 'all' AND Default_Code = 'SA')"; //$criteria = " WHERE Car_Make = '".$strMake."' AND Car_Model = '".$strModel."'"; // assign the basic sqlquery $sqlquery = $sqlSelect . $criteria; //echo $sqlquery; #debug //get the result set $result = mysql_query($sqlquery); $count = mysql_num_rows($result); $full_count = $count; //set max number of records per page $records_per_page = 999; //Next figure out how many pages you'll have. $total_pages = ceil( $count / $records_per_page ); /* This just sets up a page variable which will be past in a "next" and "prev" link. The first link to this page may not actually have $page so this just sets it up. */ if ( $page == "" ) { $page = 1; } //echo "<br>page number".$page; #debug # this will set up the "First | Prev | " part of our navigation. if ( $page == 1 ) { # if we are on the first page then "First" and "Prev" # should not be links. $naviagation = "<font color=\"#666666\">First</font> | <font color=\"#666666\">Prev</font> | "; } else { # we are not on page one so "First" and "Prev" can # be links $prev_page = $page - 1; $navigation = "<a href=\"van_steps_results.php?".$strQuery."page=1\">First</a> | <a href=\"van_steps_results.php?".$strQuery."page=".$prev_page."\">Prev</a> | "; } # this part will set up the rest of our navigation "Next | Last" if ( $page == $total_pages ) { # we are on the last page so "Next" and "Last" # should not be links // $navigation .= "<font color=\"#666666\">Next</font> | <font color=\"#666666\">Last</font>"; } else { # we are not on the last page so "Next" and "Last" # can be links $next_page = $page + 1; $navigation .= "<a href=\"van_steps_results.php?".$strQuery."page=".$next_page."\">Next</a> | <a href=\"van_steps_results.php?".$strQuery."page=".$total_pages."\">Last</a>"; } /* The final thing to do is your actual query, but first we have to figure out what the offset will be. */ $offset = ( $page - 1 ) * $records_per_page; //echo "<br>offset".$offset; #debug //create sql query $sqlSelect = "SELECT Car_Make, Car_Model, Prod_ID, Prod_Type, Prod_Model, Prod_Make, Priority, Prod_Code, Prod_REF, Product_Desc, Price_ExVat, Link, image_name, Image_Van FROM products"; $criteria = " WHERE (Car_Make = '".$strMake."' AND Car_Model = '".$strModel."' AND Default_Code = 'RS') OR (Car_Make = 'all' AND Car_Model = 'all' AND Default_Code = 'SA')"; $limit = " ORDER BY Priority ASC, Prod_Code ASC, Prod_ID ASC LIMIT $offset, $records_per_page"; // assign the basic sqlquery $sqlquery = $sqlSelect . $criteria . $limit ; //echo $sqlquery; //get the result set $result = mysql_query($sqlquery); // if no matches found from query if (!$result || (mysql_num_rows($result) == 0)){ //echo ("<b><font class=small>No matches were found.</font></b>"); } // display the results else{ // use rowcount to display total results found $count = mysql_num_rows($result); //echo $count; //echo("<p>Total Matches Found = " . $rowCount . "</p>"); //*debug } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Results Page:</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <script src="js/jquery-1.3.2.min.js" type="text/javascript"></script> <!--script src="js/jquery.lint.js" type="text/javascript" charset="utf-8"></script--> <link rel="stylesheet" href="css/prettyPhoto.css" type="text/css" media="screen" title="prettyPhoto main stylesheet" charset="utf-8" /> <script src="js/jquery.prettyPhoto.js" type="text/javascript" charset="utf-8"></script> <!-- start header graphic html --> <style type="text/css"> <!-- .table { border: 0px none; border-collapse: separate; } BODY { } A { COLOR: #003366; TEXT-DECORATION: none; } A:hover { TEXT-DECORATION: underline; color: #900; } .small { FONT-SIZE: 8pt; FONT-FAMILY: Verdana; } .std { FONT-SIZE: 8pt; FONT-FAMILY: Verdana; COLOR: #000000; } .header { FONT-SIZE: 8pt; FONT-FAMILY: Verdana; FONT-WEIGHT: BOLD; COLOR:#000000; } .bigheader { FONT-SIZE: 8pt; FONT-FAMILY: Verdana; FONT-WEIGHT: BOLD; COLOR:#FFFFFF; } .error { FONT-SIZE: 8pt; FONT-FAMILY: Verdana; COLOR:#FF0000 } .headertable { FONT-SIZE: 8pt; FONT-FAMILY: Verdana; FONT-WEIGHT: regular; COLOR:#FFFFFF; BACKGROUND-COLOR:#000066; } .stdtable { FONT-SIZE: 8pt; FONT-FAMILY: Verdana; FONT-WEIGHT: regular; COLOR:#000066; } .style16 {font-size: 11px} .style7 { color: #CC0000; font-style: italic; } .small1 { FONT-SIZE: 8pt; FONT-FAMILY: Verdana; } .header1 { FONT-SIZE: 8pt; FONT-FAMILY: Verdana; FONT-WEIGHT: BOLD; COLOR:#000000; } a:link { color: #900; } --> </style> <div align="center"> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td background=""><table width="100%" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td bgcolor="#003366"> </td> </tr> </table> <!--END header--> <table width="960" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="2"> <tr> <td><div align="center"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="arial11"><table width="100%" border="0" cellpadding="10" cellspacing="0"> <tr> <td width="33%"><p><img src="2003/results.gif" alt="" width="238" height="43" /></p> <p> </p> <p> </p></td> </tr> </table></td> </tr> </table> </div></td> </tr> </table> <table width="950" border="0" align="center" cellpadding="2" cellspacing="2" bordercolor="#FFFFFF"> <tr align="center" valign="top" class="std"> <td colspan="7"><hr width="500" size="1" /> <?php if (isset($errMessage)){ echo $errMessage; } // if no matches found from query if (!$result || (mysql_num_rows($result) == 0)) echo ("<b><font class=small>No matches were found.</font></b><br><br>"); // display the results else{ // use rowcount to display total results found echo("<br><p><em><font class=vehicle>Search Results for " . $strMake . " " . $strModel .".</em> Total Matches Found = " . $full_count . "</p>"); //*debug echo $navigation; } /* With your navigation built you can just echo that out any where you want it to appear. */ //echo $navigation; ?></td> </tr> <?php $title = "<tr align=\"center\" class=\"headertable\" height=\"32\">"; $title .= "<td width=\"95\"><img src=\"images/transparent.gif\" width=\"95\" height=\"1\" /></td>"; $title .= "<td width=\"60\">Make</td>"; $title .= "<td width=\"60\">Ref No.</td>"; $title .= "<td width=\"550\">Title/Description</td>"; $title .= "<td width=\"73\">Price Ex VAT</td>"; $title .= "<td width=\"73\">Price Inc VAT</td>"; $title .= "<td width=\"60\"><img src=\"2003/basket.gif\" width=\"21\" height=\"14\"></td>"; $title .= "</tr>"; //set the counters for the records results display screen $cnt = 0; $headercount1 = 0; $headercount2 = 0; $headercount3 = 0; $headercount4 = 0; $headercount5 = 0; $headercount6 = 0; $headercount7 = 0; while ($row = mysql_fetch_assoc($result)) { //cut the prod_type variable //get the length of the variable $strLength = strlen ($row["Prod_Type"]); //assign first 2 characters of variable $strPrefix = substr($row["Prod_Type"], 0, 2); //debug //echo "\n prefix :" . $strPrefix; //assign remaining characters of variable $strSuffix = substr($row["Prod_Type"], 2, $strLength); //debug //echo "\n suffix :" . $strSuffix; //set product header image depending on the Prod_Type Code //start the table row echo "<tr align=center><td colspan=7 class=small>"; //set bg cell color diff for BH make switch ($strPrefix) { case "BH": $color=$color2; break; default: $color=$color1; break; }//end switch switch ($strPrefix) { case "BH": if ($headercount1 == 0) { echo "<img border=0 src=2003/searchheaders/step.jpg></td></tr>"; echo $title; } $headercount1 ++; //$headercount1 break; // REMOVE ALL THIS COMMENTING IF NEEDED TO SHOW THE ROOF BARS! case "RB": // if ($headercount2 == 0) // { // echo "<img border=0 src=2003/searchheaders/NOTUSED.jpg alt=Roof-Bars></td></tr>"; // echo $title; // } // $headercount2 ++; //$headercount1 break; case "BX": if ($headercount3 == 0) { echo "<img border=0 src=2003/searchheaders/bulkheads.jpg alt=Roof-Boxes></td></tr>"; echo $title; } $headercount3 ++; //$headercount1 break; case "BR": if ($headercount4 == 0) { echo "<img border=0 src=2003/searchheaders/bulkheads.jpg alt=Bike-Racks></td></tr>"; echo $title; } $headercount4 ++; //$headercount1 break; case "SR": if ($headercount5 == 0) { echo "<img border=0 src=2003/searchheaders/bulkheads.jpg alt=Ski-Rack></td></tr>"; echo $title; } $headercount5 ++; //$headercount1 break; case "CR": if ($headercount6 == 0) { echo "<img border=0 src=2003/searchheaders/bulkheads.jpg alt=Canoe-Rack></td></tr>"; echo $title; } $headercount6 ++; //$headercount1 break; case "XD": if ($headercount7 == 0) { echo "<img border=0 src=2003/searchheaders/towbar.jpg alt=General-Accessories></td></tr>"; echo $title; } $headercount7 ++; } //end header image selection and close the table row. //echo "</td></tr>"; // if (($cnt++)%2) // { // $color="#E9E9E9"; // Almost Silver // } // else // { // $color="#E9E9E9";// Light Blue // } //print a product row if the prodtype isn't set to INFO $pop_link = ""; if ($strSuffix != "INFO"){ //test to see if an image exists for the product if ($row["Link"] <> NULL){ $pop_link = " <a href=\"products/".$row["Link"]."?iframe=true&width=650&height=500\" rel=\"prettyPhoto\" >More information >>>></a>"; } echo "<tr class=stdtable align=center height=25>"; //DISPLAY THUMB IMAGE IF ONE WAS LISTED IN THE image_name FIELD $p_Image_Van = htmlspecialchars($row["Image_Van"]); //echo "p_Image_Van:$p_image_name"; if ($p_Image_Van != "") echo "<td bgcolor=$color width=\"95\"><img src=\"images/product_images/$p_Image_Van\" border=\"0\" /></td>"; else echo "<td bgcolor=$color width=\"95\"><img src=\"images/transparent.gif\" width=\"95\" height=\"50\" border=\"0\" /></td>"; echo "<td bgcolor=$color width=\"60\">". htmlspecialchars($row["Prod_Make"]) . "</td><td bgcolor=$color width=\"60\">" . htmlspecialchars($row["Prod_REF"]) . "</td><td bgcolor=$color align=left class=\"infolink\" width=\"550\">" . htmlspecialchars($row["Product_Desc"]) . $pop_link . "</td><td bgcolor=$color width=\"73\">£" . number_format(htmlspecialchars($row['Price_ExVat']), 2) . "</td><td bgcolor=$color width=\"73\">£" . number_format((calcVAT (htmlspecialchars($row['Price_ExVat']))), 2) . "</td><td bgcolor=$color width=\"60\"><a href=basket.php?src=".urlencode($_SERVER['REQUEST_URI'])."&productID=" . $row["Prod_ID"] . "><img src=2003/buy.gif border=0></a></td></tr>"; } // if the prod type is set to INFO then print out a new row for that information else { echo "<tr class=stdtable align=center height=25 ><td colspan=7 bgcolor=$color_info><em><strong>" . htmlspecialchars($row["Product_Desc"]) . "</strong></em></td></tr>"; } } //****************************************************************************************************** /* //get all porducts from the database that are marked with prod_type XD regardless of car make and model $sqlSelectDefault = "SELECT Prod_ID, Prod_Type, Prod_Model, Prod_Make, Priority, Prod_Code, Prod_REF, Product_Desc, Price_ExVat FROM products"; $criteriaDefault = " WHERE Prod_Type LIKE '".$strDefaultProd."%'"; $limitDefault = "ORDER BY Priority ASC, Prod_Code ASC"; // assign the basic sqlquery $sqlqueryDefault = $sqlSelectDefault . $criteriaDefault . $limitDefault ; //echo $sqlquery; //get the result set $resultDefault = mysql_query($sqlqueryDefault); // if no matches found from query if (!$resultDefault || (mysql_num_rows($resultDefault) == 0)){ //echo ("<b><font class=small>No matches were found.</font></b>"); } // display the results else{ // use rowcount to display total results found $countDefault = mysql_num_rows($resultDefault); //echo $count; //echo("<p>Total Matches Found = " . $rowCount . "</p>"); //*debug } //set product header image depending on the Prod_Type Code //start the table row echo "<tr align=left><td colspan=6 class=small>"; echo "<img border=0 src=2003/searchheaders/general.jpg alt=General-Accessories>"; echo "</td></tr>"; while ($rowDefault = mysql_fetch_assoc($resultDefault)) { //cut the prod_type variable //get the length of the variable $strLengthDefault = strlen ($rowDefault["Prod_Type"]); //assign first 2 characters of variable $strPrefixDefault = substr($rowDefault["Prod_Type"], 0, 2); //debug //echo htmlspecialchars($rowDefault["Prod_ID"]); //echo "\n prefix :" . $strPrefixDefault; //assign remaining characters of variable $strSuffixDefault = substr($rowDefault["Prod_Type"], 2, $strLengthDefault); //debug //echo "\n suffix :" . $strSuffixDefault; if ($strSuffixDefault != "INFO"){ $color="#E9E9E9"; // Almost Silver //print a product row if the prodtype isn't set to INFO echo "<tr class=stdtable align=center height=25 ><td bgcolor=$color>". htmlspecialchars($rowDefault["Prod_Make"]) . "</td><td bgcolor=$color>" . htmlspecialchars($rowDefault["Prod_REF"]) . "</td><td bgcolor=$color align=left>" . htmlspecialchars($rowDefault["Product_Desc"]) . "</td><td bgcolor=$color>?" . number_format(htmlspecialchars($rowDefault['Price_ExVat']), 2) . "</td><td bgcolor=$color>?" . number_format((calcVAT (htmlspecialchars($rowDefault['Price_ExVat']))), 2) . "</td><td bgcolor=$color><a href=basket.php?src=".urlencode($_SERVER['REQUEST_URI'])."&productID=" . $rowDefault["Prod_ID"] . "><img src=2003/buy.gif border=0></a></td></tr>"; } // if the prod type is set to INFO then print out a new row for that information else { echo "<tr class=stdtable align=center height=25 ><td colspan=6 bgcolor=$color><em>" . htmlspecialchars($rowDefault["Product_Desc"]) . "</em></td></tr>"; } } */ ?> <tr align="center"> <td colspan="7" class="small1"></td> </tr> <tr> <!-- <tr align="center" class="headertable" height="32"> <td width="145">Product Name</td> <td width="178">Ref No.</td> <td width="280">Description</td> <td width="73">Price Ex VAT</td> <td width="73">Price Inc VAT</td> <td width="60"><img src="2003/basket.gif" width="21" height="14"> </td> </tr>--> <td colspan="7" height="1" bgcolor="#003366"><img src="colour_spacer.gif" width="756" height="1" /></td> </tr> </table></td> </tr> </table> <p><br /> </p> </p> <div align="center"><br /> </div> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td> </td> </tr> </table> <?php //free up some memory mysql_free_result($result); // close the aatabase connection mysql_close(); //include footer code ?> <br /> </table> </html> Similar Tutorials<a href="entries.php?eid=<?php echo $row2->eid; ?>" class="n">Entry ID <?php echo $row2->eid; ?> by <?php echo $row2->username; ?></a> My issue is that the second output of entry id works fine. The first output, being the more important, does not, even though they are identical. This will probably be something ridiculously stupid. Hi guys When I retrieve information from database into text field and update the fields, each time I press on update button, an space gets added before the text so in screenshots I have added you can see in image1 everything is fine but once I click on update, a space will be added before the text inside the text field. Here is my code <?php session_start(); include ("global.php"); //username session $_SESSION['username']=='$username'; $username=$_SESSION['username']; //welcome messaage echo "Welcome, " .$_SESSION['username']."!<p>"; if ($_POST['register']) { //get form data $name = addslashes(strip_tags($_POST['name'])); $telephonenumber = addslashes(strip_tags($_POST['telephonenumber'])); $buildingnumber = addslashes(strip_tags($_POST['buildingnumber'])); $streetname = addslashes(strip_tags($_POST['streetname'])); $town = addslashes(strip_tags($_POST['town'])); $county = addslashes(strip_tags($_POST['county'])); $country = addslashes(strip_tags($_POST['country'])); $postcode = addslashes(strip_tags($_POST['postcode'])); $email = addslashes(strip_tags($_POST['email'])); //update statements $query = "UPDATE userss SET name =' $name' WHERE username='$username'"; $result = mysql_query($query); $query = "UPDATE userss SET telephonenumber = ' $telephonenumber' WHERE username='$username'"; $result = mysql_query($query); $query = "UPDATE userss SET buildingnumber = ' $buildingnumber' WHERE username='$username'"; $result = mysql_query($query); $query = "UPDATE userss SET streetname = ' $streetname' WHERE username='$username'"; $result = mysql_query($query); $query = "UPDATE userss SET county = ' $county' WHERE username='$username'"; $result = mysql_query($query); $query = "UPDATE userss SET town = ' $town' WHERE username='$username'"; $result = mysql_query($query); $query = "UPDATE userss SET country = ' $country' WHERE username='$username'"; $result = mysql_query($query); $query = "UPDATE userss SET postcode = ' $postcode' WHERE username='$username'"; $result = mysql_query($query); $query = "UPDATE userss SET email = ' $email' WHERE username='$username'"; $result = mysql_query($query); } //update from database to txt field $update = "SELECT name, telephonenumber, buildingnumber, streetname, country, town, postcode, county, email FROM userss WHERE username='$username'"; $result = mysql_query($update); $row = mysql_fetch_assoc($result); ?> <form action='updateprofile.php' method='POST'> Name:<br /> <input type='text' name='name' value='<?php echo $row['name'];?>'><p /> Telephone Number:<br /> <input type='text' name='telephonenumber' value='<?php echo $row['telephonenumber'];?>'><p /> Building Number:<br /> <input type='text' name='buildingnumber' value='<?php echo $row['buildingnumber'];?>'><p /> Street Name:<br /> <input type='text' name='streetname' value='<?php echo $row['streetname'];?>'><p /> County:<br /> <input type='text' name='county' value='<?php echo $row['county'];?>'><p /> Town:<br /> <input type='text' name='town' value='<?php echo $row['town'];?>'><p /> Country:<br /> <input type='text' name='country' value='<?php echo $row['country'];?>'><p /> Postcode:<br /> <input type='text' name='postcode' value='<?php echo $row['postcode'];?>'><p /> Email:<br /> <input type='text' name='email' value='<?php echo $row['email'];?>'><p /> <input type='submit' name='register' value='Update'> </form> <iframe width="750" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=<?php echo "$buildingnumber,+$streetname,+$town,+ $postcode,+$county,+$country";?>&sll=&sspn=0.007597,0.025921&ie=UTF8&hq=&hnear=<?php echo "$buildingnumber,+$streetname,+$town,+ $postcode,+$county,+$country";?>&ll=&spn=0.011236,0.025921&z=14&output=embed"></iframe> could someone kindly advice me on this please? Hi guys I have created a profile page where users can update their profile. what I need to do is to echo back the users details in the inout text I have name and telephone number any ideas how to do it? here is my code <?php session_start(); include ("global.php"); //username session $_SESSION['username']=='$username'; $username=$_SESSION['username']; //welcome messaage echo "Welcome, " .$_SESSION['username']."!<p>"; if ($_POST['register']) { //get form data $name = addslashes(strip_tags($_POST['name'])); $telephonenumber = addslashes(strip_tags($_POST['telephonenumber'])); $query = "UPDATE users SET name = ' $name' WHERE username='$username'"; $result = mysql_query($query); $query = "UPDATE users SET telephonenumber = ' $telephonenumber' WHERE username='$username'"; $result = mysql_query($query); } ?> <form action='updateprofile.php' method='POST'> Company Name:<br /> <input type='text' name='name'><p /> <input type='text' name='telephonenumber'><p /> <input type='submit' name='register' value='Register'> </form> _______ the reason i want to do this is because when user is updating the name field the empty input text for telephone number ovverides the telephone number field in the database. I would aprreciate your help guys, I have peice of code which is designed enter a question into a database and the username of the person who asks the question. However, the code enters <?php echo Array; ?> into the database and not 'Tom'. I am using the same code which inserts the category of the question in the database which works. But the username comes up as <?php echo Array; ?>. Does anyone know why it shows "array"? Code: [Select] if($loggedIn) { echo "Welcome, ".$user['username'].". <a href=\"logout.php\">Logout</a>. <table width='300' border='0' align='center' cellpadding='0' cellspacing='1'> <tr> <td><form name='form1' method='post' action='phpviewquestion.php'> <table width='100%' border='0' cellspacing='1' cellpadding='3'> <tr> <td colspan='3'><strong>Your Question</strong></td> </tr> <tr> <td width='71'>Question</td> <td width='6'>:</td> <td width='600' height='50'><input name='question' type='text' id='question'></td> <td width='71'>Notes</td> <td width='6'>:</td> <td width='600' height='50'><input name='notes' type='text' id='notes'></td> </tr> <tr> <td colspan='3' align='center'><input type='image' name='image' value='Submit' src='http://www.domain.co.uk/images/submitbutton.PNG' name='image' width='100' height='53'></td> <input name='category' type='hidden' value='Furniture' id='category' > <input name='questionmaker' type='hidden' value='<?php echo $username; ?>' id='questionmaker' > </tr> </table> </form> </td> </tr> </table> </div> " ; } else { echo "Please <a href=\"login.php\">Login</a>."; } ?> i hav dis checkstatus.php page where the user enters a random number sms to him..but after tht he shud be able to see d reply given by admin ..d problem over here is d user only views half of the field called 'anything' (my database is named "proj") heres my code jst cant understand why dis is happening...pls help <html> <?php include connect.inc; $id = $_GET['id']; mysql_query("UPDATE count SET clicks=clicks+1 WHERE id='$id'"); $sql = mysql_query("SELECT link FROM count WHERE id='$id'"); $fetch = mysql_fetch_row($sql); $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { echo "Name :{$row['id']} <br>" . "Subject : {$row['link']} <br>" . "Message : {$row['count']} <br><br>"; } mysql_close(); ?> <a href='/index.php?id=1'>link1</a> <a href='/index.php?id=2'>link2</a> </html> hi all i am having a big problem that i have been trying to find out what is going on for weeks. i have a echo script that echos data that is in my database, and if i have to refresh the page it will add blank data in my database and the top echo info is blank as well. how can i fix this, and i was wanting to know how do i echo out my info in a textarea. i added a jepg to show you what i mean. here is my code echoforms.php <?php error_reporting(0); require_once('demo.php'); /*Open the connection to our database use the info from the config file.*/ $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); $sql = "SELECT company_name, contact_name, address, street_number, postcode, contact_number, contact_email, budget, description FROM 3dartactforms"; $results = mysql_query($sql); if (!$results) { die('Invalid query: ' . mysql_error()); } while($result = mysql_fetch_array( $results )){ echo '<div style="border: 1px solid #e4e4e4; padding: 15px; margin-bottom: 10px;">'; echo date("d/m/y"); echo '<p>Company Name: ' . $_POST['company_name'] . '</p>'; echo '<p>Contact Name: ' . $_POST['contact_name'] . '</p>'; echo '<p>Address: ' . $_POST['address'] . '</p>'; echo '<p>Street Number: ' . $_POST['street_number'] . '</p>'; echo '<p>Postcode: ' . $_POST['postcode'] . '</p>'; echo '<p>Contact Number: ' . $_POST['contact_number'] . '</p>'; echo '<p>Contact Email: ' . $_POST['contact_email'] . '</p>'; echo '<p>Budget: ' . $_POST['budget'] . '</p>'; echo '<p>Description: ' . $_POST['description'] . '</p>'; echo '</div>'; } ?> Here is what I am trying to accomplish: I have a students table with a studentID I also have a notes table and a sched table with studentID The sched table is working as planned where if the student is scheduled for more than one time he is displayed twice. However if there are multiple notes per student the student is display for each individual note where I would like only the most current note to be displayed Here is what the output is: 1- 10:30:00 - 10:50:00 student3 Three FST Teacher One Special1 One Writing Ratios 09/10 2- 10:30:00 - 10:50:00 student3 Three FST Teacher One Special1 One Needs to work on fractions and decimals 09/10 3- 13:00:00 - 14:00:00 student3 Three FST Teacher One Special1 One Writing Ratios 09/10 4- 13:00:00 - 14:00:00 student3 Three FST Teacher One Special1 One Needs to work on fractions and decimals 09/10 As you can see I have two notes and two schedule times for this student. what I want it to display is only line 1 & 3. which is the newest note in the system. Below is my code that I am using. Any help would be greatly appreciated. Code: [Select] <?php $result = mysql_query("SELECT * FROM students LEFT JOIN teachers ON students.teacherId = teachers.teacherId LEFT JOIN course ON students.courseId = course.courseId LEFT JOIN specialEd ON students.specialId = specialEd.specialId LEFT JOIN sched ON students.studentId = sched.studentId ORDER BY start "); echo "<table>"; while ($row = mysql_fetch_array($result)){ $id = "?id=" . $row['studentId']; echo "<tr>"; echo "<td>" . $row['start'] . " - " . $row['stop'] . "</td>"; echo "<td>" . "<a href='student.php$id'>" . $row['fName'] . " " . $row['lName'] . "</td>"; echo "<td>" . $row['courseName'] . "</td>"; echo "<td>" . $row['teachers_fName'] . " " . $row['teachers_lName'] . "</td>"; echo "<td>" . $row['special_fName'] . " " . $row['special_lName'] . "</td>"; echo "<td>" . $row['note'] . "</td>"; echo "<td>" . date("m/d", strtotime($row['started'])) . "</td>"; echo "</tr>"; } echo "</table>"; ?> Hi Guys Hoping somebody can help me again please? I have some code which calls and displays all images in the file structure on my webpage. Code: [Select] <?php //to display image from source $dir = "profpics/"; //opening directory if ($opendir = opendir($dir)) { //reading directory while (($file = readdir($opendir)) !== FALSE) { if ($file!="."&&$file!="..") echo "<img src = '$dir/$file' img width='38' img height='38'><br>"; } } ?> This works fine, but what i want is for only the image that relates to the logged in user to be displayed. Both the user id and image id are stored in the same row of my database Sorry if this is confusing. Can anybody help? Thanks Hi guys, Probably going to be a very basic question but i'm lost, i'm trying to figure out how to display an image if the value returned is equal to or greater than a certain number, more of a hypothetical question at the moment, Thanks in advance I am trying to add a background image via a custom style, but it breaks my site. I am a php novice, can someone point out my error please? The echo is being used other places on this page, so I know this code is ok: <?php echo $event->data->thumbnails['medium']; ?> but I am missing something here, this keeps breaking the page: <?php echo '<article data-style="'.$label_style.'" style="background-image:url(\<?php echo $event->data->thumbnails['medium']; ?>\")" class="mec-event-article mec-clear '.$this->get_event_classes($event).'"' . $colorful_bg_color . '>'; ?> Thanks for any help, as I learn! This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=348171.0 I'm having a really hard time getting my carousel to display in a line when I call my images from the table:
<div id="user-gallery"> <h2>Recent Images</h2> <button class="prev"><<</button> <button class="next">>></button> <?php include("file/image/upload_file.php"); $select_query = "SELECT `images_path` FROM `images_tbl` ORDER by `images_id` DESC LIMIT 9"; $sql = mysql_query($select_query) or die(mysql_error()); while($row = mysql_fetch_array($sql,MYSQL_BOTH)){ ?> <div class="anyClass"> <ul> <li><img src="<?php echo $row["images_path"]; ?>" alt="" width="125" height="70" ></li> <li><img src="<?php echo $row["images_path"]; ?>" alt="" width="125" height="70" ></li> <li><img src="<?php echo $row["images_path"]; ?>" alt="" width="125" height="70" ></li> <li><img src="<?php echo $row["images_path"]; ?>" alt="" width="125" height="70"></li> </ul> </div> <?php } ?> </div>Without the carousel it will display perfectly, but as soon as I implement it, the images won't behave normal :/ Hi, I've read a lot of places that it's not recommended to store binary files in my db. So instead I'm supposed to upload the image to a directory, and store the link to that directory in database. First, how would I make a form that uploads the picture to the directory (And what kinda directories are we talking?). Secondly, how would I retrieve that link? And I guess I should rename the picture.. I'd appreciate any help, or a good tutorial (Haven't found any myself). Hello, Five images will be displayed inside a division. There will be a previous and next button/link. If someone click the next button the next image will be added in that div and the first image will be gone from that div. The previous button/link will do the same thing. Is it possible with php? I am confused if it's a javascript or ajax question. Thanks. hey guys i have this echo (empty($info['ID_Etudiant'])? "No image": "<img src=Etudiants/".$info['photo'] ." border=0 width=100>"); the echo pic if thee is one in database works.but if there is no pic in database it shows nothing? OK, have no idea what's going on... I've done this a million times... why wont this output!?? I must have a major brain meltdown and dont know it yet!!! Code: [Select] <?php // this echoes just fine: echo $_POST['testfield']; // but this wont echo: echo if (isset($_POST['testfield'])) { $_POST['testfield'] = $test; } echo $test; /// or even this DOESNT echo either!: $_POST['testfield'] = $test; echo $test; ?> hello friends, while clicking the form all the information goes to database, I have one image upload field, when cliking the submit button, i would like 'image name' to go in database and file to go in /upload folder, i have tried this for hours and gave up, if anyone help me in this, i would be very greatful Hi All, I'm trying to echo the response from an SLA query, the query works and returns the data when I test it on an SQL application.. but when I run it on my webpage it won't echo the result. Please help? <?php $mysqli = mysqli_connect("removed", "removed", "removed", "removed"); $sql = "SELECT posts.message FROM posts INNER JOIN threads ON posts.pid=threads.firstpost WHERE threads.firstpost='1'"; $result = mysqli_query($mysqli, $sql); echo {$result['message']}; ?> Ok i have been trying for a few days now with no success to show a image from my database but as this is the first time i have tried to use databases im having no luck, my problem is this... I have an image gallery that shows a list of differnt galleries with the number of images inside it, like this.... General (10) I have a form that allows me to add new galleries to the list and upload an image to be shown in the gallery list, i simply added a field in the categories table and called it category_img. I would like to make the list of galleries look better by having an image for each one like this.... This is the code that generates and displays the list of galleries/categories but it is WAY to advanced and confusing for me to work out what to do, i have tried all sorts but only ever destroys what i already have or just does nothing at all, the closest i have got was displaying the name of the image, but no actual image. Code: [Select] <?php // initialization $result_array = array(); $counter = 0; $cid = (int)($_GET['cid']); $pid = (int)($_GET['pid']); // Category Listing if( empty($cid) && empty($pid) ) { $number_of_categories_in_row = 1; $result = mysql_query( "SELECT c.category_id,c.category_name,COUNT(photo_id) FROM gallery_category as c LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id GROUP BY c.category_id" ); while( $row = mysql_fetch_array( $result ) ) { $result_array[] = '<p><a href="gallery.php?cid=' . $row[0] . '">' . $row[1] . '</a> (' . $row[2] . ')</p>'; } mysql_free_result( $result ); $result_final = "<tr>\n"; foreach($result_array as $category_link) { if($counter == $number_of_categories_in_row) { $counter = 1; $result_final .= "\n</tr>\n<tr>\n"; } else $counter++; $result_final .= "\t<td>".$category_link."</td>\n"; } if($counter) { if($number_of_categories_in_row-$counter) $result_final .= "\t<td colspan='".($number_of_categories_in_row-$counter)."'> </td>\n"; $result_final .= "</tr>"; } } i could really do with some help as trying to learn this stuff is really hard when i have to work in my living room with children running around, my head has not stopped hurting in days. |