PHP - Convert Text To Link Which Retrieve From Database
Code: [Select]
<?php echo $row_Recordset1['name']; ?> i want to convert the name in to like <a href=main.php?name= $row_Recordset1['name'] >> in databse i has 3 name Steve Mark Lisa i want that names into link like main.php?name=mark and so on how to do it help me h Similar Tutorials
Query About How To Retrieve A Password From The Database And Compare To The One The User Has Entered
Hello.
I have a bit of a problem. When I fetch the link field from the database.i don't see an actual link on the page.
One more thing, what type of field should I use to store the link in the database? Probably there is where I went wrong.
All help is
Hi Support, I have a form, where it collects user description input. I can collect the inputs and store it with newline. The issue is - how to collect the http link to actual hyperlink ref during display. The following is my code: <textarea name="description" cols="50" rows="10" id="description"><?php echo str_replace("<br>", "\n", $description);?></textarea></td> For example, User input: Hi, Check it out - http://www.google.com/ I would like to display google link as href so that Viewers can click the link and go to the page. Right now, it is not href and user need to copy the link to new tabs or pages and then it can come. Thanks for your help. Regards, Ahsan Hello all! I am somewhat new to PHP and SQL, but I think I have a basic understanding of how the language works. I have read through a million different websites and forums, and have tried a million different ways but am just not getting anywhere! This is what I am trying to do... I have a text link that I want to click through to an outside URL from my website. This outside URL was already entered into an SQL database, and I just cant seem to get the text link to bring up the outside URL from the database. This is what I have so far... 1.) My webpage that I am working on is www.mywebsite.com/articles.php 2.) I want the text "Read more..." on this webpage to click through to an outside URL, like "http://www.google.com", which was already entered into an SQL database under the title of "article_link" in a new window 3.) So I would like for "Read more..." to click through the outside URL that was entered into "article_link" in the database Code: [Select] <?php echo <p><a href="\' . $article_link . '\" target="_blank">Read more...</a></p>; ?> Nothing I have tried has worked so far, nothing clicks through to the outside URL in the "article_link" entry from the database. Sorry if I am being redundant, I have been at this all day! Please help and thank you in advance!! I have this code which uoploads and resizes the images into a folder without a problem. My problem is I am unable to view the Thumb or Full image which has uploaded to the folder and the database with the other data. How do i correct this problem code below. Thanks upload form and script Code: [Select] <?php //database properties $dbhost = 'localhost'; $dbuser = 'user'; $dbpass = 'pass'; $dbname = 'DB'; // make a connection to mysql here $conn = mysql_connect ($dbhost, $dbuser, $dbpass) or die ("I cannot connect to the database because: " . mysql_error()); mysql_select_db ($dbname) or die ("I cannot select the database '$dbname' because: " . mysql_error()); /******** start function ********/ function errors($error){ if (!empty($error)) { $i = 0; echo "<blockquote>\n"; while ($i < count($error)){ echo "<p><span class=\"warning\">".$error[$i]."</span></p>\n"; $i ++;} echo "</blockquote>\n"; }// close if empty errors } // close function // ----------------Create Smaller version of large image--------------------- function createthumbfull($src_filename, $dst_filename_full) { // Get information about the image list($src_width, $src_height, $type, $attr) = getimagesize( $src_filename ); // Load the image based on filetype switch( $type ) { case IMAGETYPE_JPEG: $starting_image = imagecreatefromjpeg( $src_filename ); break; case IMAGETYPE_PNG: $starting_image = imagecreatefrompng( $src_filename ); break; case IMAGETYPE_GIF: $starting_image = imagecreatefromgif( $src_filename ); break; default: return false; } // get the image to create thumbnail from $starting_image; // get image width $width = imagesx($starting_image); // get image height $height = imagesy($starting_image); // size to create thumnail width $thumb_width = 600; // divide iwidth by specified thumb size $constant = $width/$thumb_width; // round height by constant and add t thumb_height $thumb_height = round($height/$constant, 0); //create thumb with true colours $thumb_image = imagecreatetruecolor($thumb_width, $thumb_height); //create thumbnail resampled to make image smooth imagecopyresampled($thumb_image, $starting_image, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height); $ran = rand () ; $thumb1 = $ran.".jpg"; global $thumb_Add_full; $thumb_Add_full = $dst_filename_full; $thumb_Add_full .= $thumb1; imagejpeg($thumb_image, "" .$dst_filename_full. "$thumb1"); } //-------------------- create thumbnail -------------------------------------------- //$src_filename = source of image //$dst_filename_thumb = location to store final image function createthumb($src_filename, $dst_filename_thumb) { $size = getimagesize($src_filename); // get image size $stype = $size['mime']; //get image type : gif,png,jpg $w = $size[0]; // width of image $h = $size[1]; // height of image //do a switch statment to create image from right image type switch($stype) { //if image is gif create from gif case 'image/gif': $simg = imagecreatefromgif($src_filename); break; //if image is jpeg create from jpeg case 'image/jpeg': $simg = imagecreatefromjpeg($src_filename); break; //if image is png create from png case 'image/png': $simg = imagecreatefrompng($src_filename); break; } $width = $w; // get image width $height = $h; // get image height // size to create thumnail width $thumb_width = 150; $thumb_height = 150; //use true colour for image $dimg = imagecreatetruecolor($thumb_width, $thumb_height); $wm = $width/$thumb_width; //width divided by new width $hm = $height/$thumb_height; //height divided by new height $h_height = $thumb_height/2; //ass new height and chop in half $w_height = $thumb_width/2; //ass new height and chop in half //if original width is more then original height then modify by width if($w> $h) { $adjusted_width = $w / $hm; // add original width and divide it by modified height and add to var $half_width = $adjusted_width / 2; // chop width in half $int_width = $half_width - $w_height; // take away modified height from new width //make a copy of the image imagecopyresampled($dimg,$simg,-$int_width,0,0,0,$adjusted_width,$thumb_height,$w,$h); //else if original width is less or equal to original height then modify by height } elseif(($w <$h) || ($w == $h)) { $adjusted_height = $h / $wm; // diving original height by modified width $half_height = $adjusted_height / 2; // chop height in half $int_height = $half_height - $h_height; // take away modified height from new width //make a copy of the image imagecopyresampled($dimg,$simg,0,-$int_height,0,0,$thumb_width,$adjusted_height,$w,$h); } else { // don't modify image and make a copy imagecopyresampled($dimg,$simg,0,0,0,0,$thumb_width,$thumb_height,$w,$h); } $ran = "thumb_".rand (); // generate random number and add to a string $thumb2 = $ran.".jpg"; //add random string to a var and append .jpg on the end global $thumb_Add_thumb; //make this var available outside the function as it will be needed later. $thumb_Add_thumb = $dst_filename_thumb; // add destination $thumb_Add_thumb .= $thumb2; // append file name on the end //actually create the final image imagejpeg($dimg, "" .$dst_filename_thumb. "$thumb2"); } /********end functions ***********/ // if form submitted then process form if (isset($_POST['submit'])){ // check feilds are not empty $imageTitle = trim($_POST['imageTitle']); if (strlen($imageTitle) < 3 || strlen($imageTitle) > 255) { $error[] = 'Title must be at between 3 and 255 charactors.'; } // check feilds are not empty or check image file size if (!isset($_FILES["uploaded"])) { $error[] = 'You forgot to select an image.'; } // check feilds are not empty $imageDesc = trim($_POST['imageDesc']); if (strlen($imageDesc) < 3) { $error[] = 'Please enter a description for your image.'; } // location where inital upload will be moved to $target = "productimages/" . $_FILES['uploaded']['name'] ; // find the type of image switch ($_FILES["uploaded"]["type"]) { case $_FILES["uploaded"]["type"] == "image/gif": move_uploaded_file($_FILES["uploaded"]["tmp_name"],$target); break; case $_FILES["uploaded"]["type"] == "image/jpeg": move_uploaded_file($_FILES["uploaded"]["tmp_name"],$target); break; case $_FILES["uploaded"]["type"] == "image/pjpeg": move_uploaded_file($_FILES["uploaded"]["tmp_name"],$target); break; case $_FILES["uploaded"]["type"] == "image/png": move_uploaded_file($_FILES["uploaded"]["tmp_name"],$target); break; case $_FILES["uploaded"]["type"] == "image/x-png": move_uploaded_file($_FILES["uploaded"]["tmp_name"],$target); break; default: $error[] = 'Wrong image type selected. Only JPG, PNG or GIF accepted!.'; } // if valadation is okay then carry on if (!$error) { // post form data $imageTitle = $_POST['imageTitle']; $imageDesc = $_POST['imageDesc']; //strip any tags from input $imageTitle = strip_tags($imageTitle); $imageDesc = strip_tags($imageDesc); // add slashes if needed if(!get_magic_quotes_gpc()) { $imageTitle = addslashes($imageTitle); $imageDesc = addslashes($imageDesc); } // remove any harhful code and stop sql injection $imageTitle = mysql_real_escape_string($imageTitle); $imageDesc = mysql_real_escape_string($imageDesc); //add target location to varible $src_filename $src_filename = $target; // define file locations for full sized and thumbnail images $dst_filename_full = 'productimages/'; $dst_filename_thumb = 'productthumb/'; // create the images createthumbfull($src_filename, $dst_filename_full); //call function to create full sized image createthumb($src_filename, $dst_filename_thumb); //call function to create thumbnail image // delete original image as its not needed any more. unlink ($src_filename); // insert data into images table $query = "INSERT INTO table (imageTitle, imageThumb, imageFull, imageDesc) VALUES ('$imageTitle', '$thumb_Add_thumb', '$thumb_Add_full', '$imageDesc')"; $result = mysql_query($query) or die ('Cannot add image because: '. mysql_error()); // show a message to confirm results echo "<h3 align='center'> $imageTitle uploaded</h3>"; } } //dispaly any errors errors($error); ?> <form enctype="multipart/form-data" action="" method="post"> <fieldset> <legend>Upload Picture</legend> <p>Only JPEG, GIF, or PNG images accepted</p> <p><label>Title<br /></label><input type="text" name="imageTitle" <?php if (isset($error)){ echo "value=\"$imageTitle\""; }?> /></p> <p><label>Image<br /></label><input type="file" name="uploaded" /></p> <p><label>Description<br /></label><textarea name="imageDesc" cols="50" rows="10"><?php if (isset($error)){ echo "$imageDesc"; }?></textarea></p> <p><label> </label><input type="submit" name="submit" value="Add Image" /></p> </fieldset> </form> view data Code: [Select] <?php // Connects to your Database mysql_connect("localhost", "user", "pass") or die(mysql_error()) ; mysql_select_db("DB") or die(mysql_error()) ; //Retrieves data from MySQL $data = mysql_query("SELECT * FROM table") or die(mysql_error()); //Puts it into an array while($info = mysql_fetch_array( $data )) { ?> <?php echo "<img src=http://www.web.com/productimages/" .$info['imagefull'] ." > <br>"; ?> <?php echo "<img src=http://www.web.com/productthumb/" .$info['imageThumb'] ." > <br>"; ?> <?php echo "<b>imageTitle:</b> ".$info['imageTitle'] . "<br> "; ?> <?php echo "<b>imageDesc:</b> ".$info['imageDesc'] . " <hr>"; ?> <?php }?> CAN ANYONE TELL ME WHAT i AM DOING WRONG. I WANT TO RETRIEVE THE VERY FIRST RECORD IN MY DATABASE WHEN THE CODE EXECUTE IT ONLY SHOWS THE LAST RECORD IN THE DATABASE <?PHP $thisMonth = date('M'); $thisDay = date('j'); $eventMonth = array(); $eventDay = array(); $eventTime = array(); $eventName = array(); $eventLocation = array(); $dbMonth=""; $dbDay=""; $i=0; $conn = odbc_connect('eventsDB','',''); $sql= "SELECT month,day, time, event,location FROM Events"; $rs="$conn,$sql"; if (!$conn) { exit("Connection Failed: " . $conn); } $rs=odbc_exec($conn,$sql); if(!$rs) { exit("Error in SQL"); } echo "DATABASE OPEN"; while($i<3) { $dbMonth= odbc_result($rs,"month"); echo $eventMonth[$i]=odbc_result($rs,"month")."\n"; if($dbMonth<>$thisMonth) { odbc_fetch_row($rs); } echo $eventMonth[$i]=odbc_result($rs,"month")."\n"; echo $eventDay[$i]=odbc_result($rs,"day")."\n"; echo $eventTime[$i]=odbc_result($rs,"time")."\n"; echo $eventDay[$i]=odbc_result($rs,"event")."\n"; echo $eventLocation[$i]=odbc_result($rs,"location")."\n"; $i++; odbc_fetch_row($rs); echo $i; } //ends while loop odbc_close($conn); ?> I AM WORKING ON A PROJECT , I NEED YOUR HELP. I WANT TO USE EXISTING SRC OF IFRAME + RETRIVED VALUE FROM DATABASE INTO IFRAME This is my data.php to retrive values from database into iframe without refresh web page.
<?php $conn = new mysqli('localhost', 'root', '', 'x'); if ($conn->connect_error) { die("Connection error: " . $conn->connect_error); } $result = $conn->query("SELECT number1 FROM users"); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { echo $row['number1'] . '<br>'; } } ?>
<?php include('data.php') ?> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> </head> <body> <div id="show"></div> <script type="text/javascript" src="jquery-3.1.1.min.js"></script> <script type="text/javascript"> $(document).ready(function() { setInterval(function () { $('#show').load('data.php') }, 1000); }); </script> <iframe id="w3" src="DATABASE RETRIVED VALUE" height="80px" width="300px" frameborder="0" style="border: 0; width:300px; height:80px; background-color: #FFF;"></iframe> </body> </html>
INDEX FILE CODES CAN SUCCESSFULLY RETRIVE VALUES FROM DATABASE BUT, I WANT TO STORE IT IN IFRAME SRC . VAR= URLS = 'HTTP://WWW.GOOGLE.COM' IFRAME SRC WILL BE VAR URLS + RETRIEVED VALUE FROM DATABASE
hi, i have a form that requires image to be uploaded. i know how to store the form values in a database but i don't know how to store the image into the database. i want the user to upload picture and preview the data provided review (including the image) before submitting to the database. thanks I have code for displaying result from database:
foreach ($_SESSION["products"] as $cart_itm) { $product_code = $cart_itm["code"]; $results = $mysqli->query("SELECT * FROM products WHERE product_code='$product_code' LIMIT 1"); $obj = $results->fetch_object();Now, I display data with: $obj->product_name When I get the list, how to put inline numbers (1 2 3 4 ...)? 1 products1 2 products1 3 products1 4 products1.. Hi, Im trying to retrieve HTML from a mysql database but nothing i've tried seems to work. The HTML im trying to retrieve is an iframe with a link and styles (code from amazon associates). Im trying to display links to specific products on amazon from the product page on my site. All data about the product is retrieved from the database so i have code to select the amazon link row in my database table but i cant get it to display. It says the html isnt a string so i cant echo it, fair enough. I have tried using the following code: Code: [Select] $get_buylink_sql = "SELECT mobo_buylink FROM mobo WHERE mobo_id = $mobo_id"; $get_buylink_res = mysqli_query($mysqli, $get_buylink_sql) or die(mysqli_error($mysqli)); while ($buylink = mysqli_fetch_array($get_buylink_res)) { echo"<iframe src=\"".$buylink."\" style=\"width:120px;height:240px;\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\"></iframe>"; } mysqli_free_result($get_buylink_res); mysqli_close($mysqli);I have also tried putting the whole iframe code in the database which didnt work either. The mobo_id variable works fine for retrieving the rest of the data and i need to get the amazon link from the same record. I hope i've put this in a way you can understand, but if not i'll try and explain better and give you a link to my site if needed. Thanks, Alex Hello people, I have created an application in Code Charge where my site users can login and play games online.The game code is run via flash and html. The Game has 5 stages and from a page in my application called transfertogame.php , i transfer them to the game page. Now i want to be able to track each players progress via database so that when they log back in and they get to the transfertogame.php page, it can check the page they were on before and immediately take them to the page without starting from page 1. Any help will be appreciated as i am very poor with php scripting This is the session ID i guess is being used from my application page //Initialize Method @4-537EA73F function Initialize() { if(!$this->Visible) return; $this->ds->Parameters["sesUserID"] = CCGetSession("UserID"); } //End Initialize Method //Validate Method @4-7E1FC38C function Validate() { $Validation = true; $Where = ""; $this->CCSEventResult = CCGetEvent($this->CCSEvents, "OnValidate"); return (($this->Errors->Count() == 0) && $Validation); } //End Validate Method Hi, after following lots of advice and changing to MySqli I am running into a few probs. This is me just probably missing something stupid, I know what I want, but can't figure out what query I should use and where I should place it. All the queries I have tried have failed.
I just need a query that gets the $current_stored_password from the password field on the database, to confirm the last check
elseif ($current_password !== $current_stored_password) { include 'includes/overall/header.php'; echo $current_password . ' AND ' . $_POST['current_password'] . ' Password and password again do not match'; include 'includes/overall/header.php'; }Here is the whole script. <?php session_start(); error_reporting(0); //ini_set('display_errors', '1'); require( 'database.php' ); $username = $_SESSION['loggedinuser']; $current_stored_password = $_SESSION['password']; $current_password = $_POST['current_password']; $password = mysqli_real_escape_string($con, md5( $_POST['password'])); $password_again = mysqli_real_escape_string($con, md5( $_POST['password_again'])); // Run checks if (isset($_POST['current_password'], $_POST['password'], $_POST['password_again'])) { if( strlen( $_POST['current_password'] ) < 8 ) { include('includes/overall/header.php'); echo "Password Must Be 8 or More Characters."; include('includes/overall/footer.php'); } elseif( strlen( $_POST['password'] ) < 8 ) { include('includes/overall/header.php'); echo "Password Must Be 8 or More Characters."; include('includes/overall/footer.php'); } elseif ( strlen( $_POST['password_again'] ) < 8 ) { include('includes/overall/header.php'); echo "Password Must Be 8 or More Characters."; include('includes/overall/footer.php'); } elseif ($password !== $password_again) { include 'includes/overall/header.php'; echo ' Password and password again do not match'; include 'includes/overall/header.php'; } elseif ($current_password !== $current_stored_password) { include 'includes/overall/header.php'; echo $current_password . ' AND ' . $_POST['current_password'] . ' Password and password again do not match'; include 'includes/overall/header.php'; } else { // Define a query to run $query = "UPDATE `user` SET `password` = '$password' WHERE `username` = '$username'"; // Query the database $result = mysqli_query($con,$query); // Check if the query failed if( !$result ) { die('There was a problem executing the query ('.$query.'):<br>('.mysqli_errno($con).') '.mysqli_error($con)); } else { include 'includes/overall/header.php'; echo 'Password has been changed'; include 'includes/overall/footer.php'; } } } // Close the connection mysqli_close($con); ?>At the moment the message displayed when the form is submitted is echo $current_password . ' AND ' . $_POST['current_password'] . ' Password and password again do not match';How do I retrieve the password from the database to compare against the current password entered by the user? Any help is much appreciated. PS. Yes I know I have repeated code and that md5 is not secure, but I am just building onto a template I got and will be making changes to shorten the code and secure the password soon Am a newbie in php. Since I can't insert values to the database with respect to a user Id or with any other token using WHERE clause. I.e "INSERT INTO receipts(date) VALUES(example) where id="**....." If I need to fetch several values of column for a particular user, how do I go about it? Thank you!!! As a complete newbie to php and webdesigning i have a following problem.I would like to retrieve the data from database and display it in a drop down menu.Then i should allow the user to select the values from drop down list along with other details,in other words i have to embed the drop down output as the form input for the user and store the form data in another table.I am running a xampp server and i am using php 5.4 version.Please help.My code is as follows.In this case project_name is displayed as the drop down output.but how do i use the same drop down output as a input in the form. <html> <head></head> <body> <?php error_reporting(E_ALL ^ E_DEPRECATED); include 'connect.php' ; $tbl_name="projects"; $sql="SELECT project_name FROM $tbl_name "; $result=mysql_query($sql); if($result === FALSE) { die(mysql_error()); } ?> <form name="resources" action="hourssubmit.php" method="post" > <?php echo "<select name='project_name'>"; while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['project_name'] ."'>" . $row['project_name'] ."</option>"; } echo "</select>"; ?> </form> </body> </html> i have 8 division (div), i want to display 4 rows in 4 division and the remain 4 rows in the next 4 division here is my code structure for carousel
<div class="nyie-outer"> second row third row
fourth row fifth row sixth row seven throw eighth row
</div><!--/.second four rows here-->
sql code
CREATE TABLE product( php code
<?php how can i echo that result in those rows
Hello everybody. Have a good day. I'm Lam, I have problem hope you help me. 1. This is content html Quote <img src="http://example.com/logo.png" /> anti http://google.com<br /> and http://bing.com I want convert to Code: [Select] <img src="http://example.com/logo.png" /> anti <a href="http://google.com">http://google.com</a><br /> and <a href="http://bing.com">http://bing.com</a> and this code php Code: [Select] preg_replace("/(http:\/\/[a-zA-Z-0-9._?\/\s]+)/", "<a href=\"$1\">$1</a>", $content); but result Code: [Select] <img src="[color=red]<a href="http://example.com/logo.png">http://example.com/logo.png</a>[/color]" /> anti <a href="http://google.com">http://google.com</a><br /> and <a href="http://bing.com">http://bing.com</a> I can help me I speak English not well hope u ignoring thanks. I coded the following but some parts are not working (the "curveball" mentioned at the end). How would YOU do this? I have a page (A) displaying a form with a textarea field using a WYSIWYG interface. The user will enter a list of unordered items and upon submit the string will look something like this: This is my list of food items: <ul> <li> Lettuce </li> <li> Tomatoes </li> <li> Eggs </li> <ul> Upon submit, I need to give each list item an unique id and store this id along with the text next to it in a separate table: List_item_id List_item_text List_item_state food_1 Lettuce food_2 Tomatoes food_3 Eggs The user will then land in another page with a form displaying the list. The text is now in the page itself and not in a textarea. Instead of the bullets a dropdown list appears, and the user can select "buy" or "sell" for each list item. This page (B) looks something like this: <form> This is my list of food items: <br><select name="food_1"> <option value="buy">Buy</option> <option value="sell">Sell</option> </select> Lettuce <br><select name="food_2"> <option value="buy">Buy</option> <option value="sell">Sell</option> </select> Tomatoes <br><select name="food_2"> <option value="buy">Buy</option> <option value="sell">Sell</option> </select> Eggs <input type=submit value="submit"> </form> When the user hits "submit" the table with the list items will be updated with the values selected in the dropdown list: List_item_id List_item_text List_item_state food_1 Lettuce Buy food_2 Tomatoes Buy food_3 Eggs Sell The next time the user goes to Page B the list will remember the states. Here's the curveball: At any point the user may click on "EDIT LIST" on Page B so they may add more items (at the begining, middle or end of the string). On edit mode the list items should appear as bullets again inside the WYSIWYG interface. Keep in mind that some of the text in the string may not be a list item (ie, "this is my list of food...") Hi, I want to be able to let user type in xml text and it will be parsed and uploaded to db, but it doesn't work, it just keeps redirecting me back to this form below! here is html form: Code: [Select] <html> <body> <form method='post' method='form.php'> <p> <textarea name="pastedXML" rows="10" cols="30"> Please paste your xml file here. </textarea> </p> <p> <input type="submit" value="Convert to SQL" name="textXML" /> </p> </form> </body> </html> Here is script (form.php;I just want to retrieve the contents typed in text area to store to variable...how??) Code: [Select] <?php //get the text in textarea and shred it! if(isset($_POST['textXML'])) print $_POST['pastedXML']; ?> Any help much appreciated! I've been playing around with this code from http://v3.thewatchmakerproject.com/journal/276/building-a-simple-php-shopping-cart Objective: I'm trying to make the scripts work but without pulling the data from MySQL Database. Instead, I created an array and inserted some info there and trying to replicate the same results but getting confused. For example, on the Index.php file, I made the following changes: <?php // Start the session session_start(); // Include functions require_once('inc/functions.inc.php'); // Products multidimensional Array $products = array("book" => array( 'id' => '1', 'title' => 'Learn Your ABC\'s', 'author' => 'John Doe', 'price' => '14.95'), "video" => array('id' => '2', 'title' => 'Visual Guide to learn', 'author' => 'Adam Smith', 'price' => '21.38'), "puzzle" => array('id' => '3', 'title' => 'Can You Solve?', 'author' => 'Sara Brown', 'price' => '9.41'), "exam" => array('id' => '4', 'title' => 'Test Your Knowledge', 'author' => 'Kim Carver', 'price' => '11.15')); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>PHP Shopping Cart Demo &#0183; Bookshop</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Your Shopping Cart</h1> <?php echo writeShoppingCart(); ?> </div> <div id="booklist"> <h1>Books In Our Store</h1> <?php /* $sql = 'SELECT * FROM books ORDER BY id'; $result = $db->query($sql); $output[] = '<ul>'; while ($row = $result->fetch()) { $output[] = '<li>"'.$row['title'].'" by '.$row['author'].': $'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; } $output[] = '</ul>'; echo join('',$output); */ ?> <?php $output[] = '<ul>'; foreach ($products as $product => $product_item) { // $flavor is the key and $piece is the value foreach ($product_item as $item => $piece) { if ($item == "id") { # Conditional logic defined to map specific keys to specified name value $row['id'] = $piece; // echo "The id is ". $id."<br />"; // set just to confirm value correct for variable } elseif ($item == "title") { # Conditional logic defined to map 1st key to price value $row['title'] = $piece; // echo "The title is ". $title."<br />"; // set just to confirm value correct for variable } elseif ($item == "author") { # Conditional logic defined to map 1st key to price value $row['author'] = $piece; // echo "The author is ". $author."<br />"; // set just to confirm value correct for variable } elseif ($item == "price") { # Conditional logic defined to map 1st key to shipping value $row['price'] = $piece; // echo "Price: ". $price."<br /><br />"; // set just to confirm value correct for variable } $output[] = '<li>"'.$row['title'].'" by '.$row['author'].': $'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; $output[] = '</ul>'; echo join('',$output); } } ?> </div> </body> </html> And here's the original index.php before my edits which show the sql query to the db: <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>PHP Shopping Cart Demo &#0183; Bookshop</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Your Shopping Cart</h1> <?php echo writeShoppingCart(); ?> </div> <div id="booklist"> <h1>Books In Our Store</h1> <?php $sql = 'SELECT * FROM books ORDER BY id'; $result = $db->query($sql); $output[] = '<ul>'; while ($row = $result->fetch()) { $output[] = '<li>"'.$row['title'].'" by '.$row['author'].': £'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; } $output[] = '</ul>'; echo join('',$output); ?> </div> </body> </html> Also, I included the zipped file of the entire script setup. Again, I'm trying to figure out how to make the cart work with using an array for the product instead of MySQL database. My goal is to remove ALL SQL statements from the scripts but stuck with the looping portion to display the title, author, and price from the array as shown above. Hi I've got this database I created with fields ProductId ProductName Image I've managed to get it to list the ID,productname, and Image urls in a list. My next step is to have the image field actually display an image and make it clickable: heres what I've done so far: Code: [Select] <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("productfeed", $con); $result = mysql_query("SELECT * FROM productfeeds"); echo "<table border='0'> <tr> <th>Firstname</th> <th>Lastname</th> <th>Image</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['ProductID'] . "</td>"; echo "<td>" . $row['ProductName'] . "</td>"; echo "<td>" . $row['ImageURL'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> Heres what I want to do: Code: [Select] while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['ProductID'] . "</td>"; echo "<td>" . $row['ProductName'] . "</td>"; // my changes beneath echo "<td>" . <a href="<?php echo $row['ImageURL'];?>"> <img src="<?php echo $row['LinkURL']; ?>"> </a>. "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> Can you guys point me in the right direction? Many thanks I wonder whether someone may be able to help me please. I'm fairly new to PHP programming so please bear with me. I currently have a HTML user input form, where two of the fields are dependable drop down boxes. The user selects text values from these and, along with other pieces of information, the record is saved to a mySQL database. However, rather than saving the text value I save the 'id' field value for each selection made. On another 'Read Only' form, the user can then go back to have a look at the records they have previously saved. The problem I have is that rather than the user being able to see the text values selected from the drop down menus, they can only see the id for each of the selections made. I just wondered whether it would be at all possible please that someone could show me what I need to do so that the user can see the 'text' rather than the 'id' value from the selections they have made. The code that I am using to load the information into the read only form is below. Code: [Select] <?php require("phpfile.php"); // Start XML file, create parent node $dom = new DOMDocument("1.0"); $node = $dom->createElement("markers"); $parnode = $dom->appendChild($node); // Opens a connection to a MySQL server $connection=mysql_connect ("hostname", $username, $password); if (!$connection) { die('Not connected : ' . mysql_error());} // Set the active MySQL database $db_selected = mysql_select_db($database, $connection); if (!$db_selected) { die ('Can\'t use db : ' . mysql_error()); } // Select all the rows in the table $query = "SELECT findid, locationid, detectorid, searchheadid "; $result = mysql_query($query); if (!$result) { die('Invalid query: ' . mysql_error()); } header("Content-type: text/xml"); // Iterate through the rows, adding XML nodes for each while ($row = @mysql_fetch_assoc($result)){ // ADD TO XML DOCUMENT NODE $node = $dom->createElement("marker"); $newnode = $parnode->appendChild($node); $newnode->setAttribute("findid",$row['findid']); $newnode->setAttribute("locationid",$row['locationid']); $$newnode->setAttribute("detectorid",$row['detectorid']); $newnode->setAttribute("searchheadid",$row['searchheadid']); } echo $dom->saveXML(); ?> The two fields concerned are 'detectorid' and 'searchheadid'. The tables holding the 'id' and 'text' values for each are in the following tables 'detectors' and searchheads'. Many thanks and kind regards Chris |