
plugnz
Members-
Posts
21 -
Joined
-
Last visited
Never
Everything posted by plugnz
-
Joining two tables and limiting data from only 1
plugnz replied to plugnz's topic in PHP Coding Help
aw read about that GROUP BY but didn't quite get it! Thanks heaps. -
Hi Everyone, I am having fun trying to sort out a way of joining two tables but only limiting the data from one of them. Here's my plan... I have one database that holds category names ( ie boats,ships,cars) and another that holds images that relate to those category names. ( ie boat1.jpg,boat2.jpg,ship1.jpg,ship2.jpg,car1.jpg etc). What I want to do is display just 1 image from each of those category names alongside the category names.. ie boat,boat1.jpg, ship,ship1.jpg,car,car1.jpg.... at this point it doesn't matter which image comes from each category as long as it's only one image rather than all of them. I have tried to limit but only end up with 1 image from 1 category. heres my select query... $query = "SELECT ctg.category_id, ctg.category_name, img.image_id " . "FROM cms_categories ctg " . "INNER JOIN cms_images_category img " . "ON ctg.category_name = img.name_category " . "WHERE ctg.category_id " . "ORDER BY category_name " . "LIMIT 1 "; $results1 = mysql_query($query,$conn) or die(mysql_error()); while ($row1 = mysql_fetch_array($results1)) { extract($row1); $images = $ImageThumb . $image_id . ".jpg"; echo "<td class='uploadimg1'><a href =\"".$ImageDir . $image_id . ".jpg\" target='top'>"; echo "<img src=\"".$images . "\"></a>\n"; echo '<h2><a href ="search1.php?category=' . $row1['category_name'] . '">' . htmlspecialchars($row1['category_name']) . "</a></h2\n"; echo ($x % 5 == 0)? "</tr><tr>" : ""; $x++; } Any thoughts? Thanks in advance....
-
Hi there, This is one of those really annoying questions that is probably so obvious but I just can t see it. I'm trying to delete some rows from my database which have been selected from a drop down box in my form. Heres the code echo " <td width = '50%'>"; echo ' <br><select name="category_name" size="1" > '; echo ' <optgroup label="-----------------------------------------">'; $query = "SELECT category_id, category_name " . "FROM cms_categories " . "ORDER BY category_name ASC"; $results = mysql_query($query,$conn) or die(mysql_error()); while ($row = mysql_fetch_array($results)) { extract($row); echo ' <option selected value="' . $row['category_name'] . '" selected="selected">'. htmlspecialchars($row['category_name']); } echo " </option></optgroup>\n"; echo " </select>\n"; echo ' <input type="hidden" name="category_id" value="' . $row['category_id'] . "\">\n"; echo ' <input type="submit" class="submit" name="action" ' . "value=\"Delete Category\"></td></tr>\n"; Plus... case 'Delete Category': if (isset($_POST['category_name']) and isset($_POST['category_id'])) { $sql = "DELETE FROM cms_categories " . "WHERE category_name= " . $_POST['category_name'] . "AND category_id=" . $_POST['category_id']; mysql_query($sql, $conn) or die('Could not DELETE category; ' . mysql_error()); And here's the error message: have tried $_GET instead of $_POST and get no error but the rows don't get deleted either. If I take out the category_id part all together i get the following error message Which tells me that the category name data is being passed ok so I'm guessing its the category_id hidden field thats upsetting it... I have tried replacing the $_POST[] with the actual data and that works so somehow the database is not receiving the right info to make it work. any thoughts why this is not working? Thanks in advance
-
Cor thats the closest so far... just a few tweaks needed. for some reason the first image seems to want to occupy the whole row by itself, with the rest doing as they're told and then how do I make it so the images only fill the available screen width rather than a select number wide? I want it to fill the screen as much as possible. But thanks every one
-
Hey thanks, tried it and works great for numbers but when I apply it to the images i get 100 times each image unless I change $ct to 1 and then the images don't wrap they just keep going to the right. $ct=100; for($i=1;$i<=$ct;$i++) { echo "<td><a href =\"".$ImageDir . $image_id . ".jpg\" target='top'>"; echo "<img src=\"".$images . "\"></a></td>"; if($i%10==0)echo "</tr>\n"; } if I try to attach [$i] to end of $images i lose the image path and still get the repeats.
-
Hi BillyBoB, $image_id is set in the database echo "<table>"; echo "<tr ><td >"; echo "<h1>Category: " . $category_name . " </h1>\n"; echo "</td></tr>"; $ImageDir = "img/category/"; $ImageThumb = $ImageDir . "thumbnails/"; $getpic = "SELECT image_id, image_group, image_name, location_no " . //$getpic = "SELECT image_id " . "FROM cms_images_category " . "WHERE category_name = '" . $_GET['category'] . "'"; "ORDER BY image_group "; $results = mysql_query($getpic,$conn) or die(mysql_error()); while ($row = mysql_fetch_array($results)) { extract($row); $images = $ImageThumb . $image_id . ".jpg"; $y=0; $x=1; $i=2; for ($y=1;$y<=1;$y++) { echo "<tr>"; for ($x=1;$x<=5;$x++) { echo "<td>$image_id </td>"; } echo "</tr>"; } Thanks
-
Ok, This is probably php 101 but I just cannot get the for loop to do what I want it to do. I've been trying to display images from the database horizontally on the page. I keep losing the image so I've decided to go back to basics to try it with some text. What I want is this.... 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 but i get this... 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 3 the code looks like this... $y=0; $x=1; $i=2; for ($y=1;$y<=1;$y++) { echo "<tr>"; for ($x=1;$x<=5;$x++) { echo "<td>$image_id </td>"; } echo "</tr>"; } Ant ideas how to make this work???
-
Hi sorry, error I'm getting is :
-
still trying to get my head around this multi image upload thing. Found this.... while(list($key,$value) = each($_FILES[images][name])) { if(!empty($value)){ // this will check if any blank field is entered $filename = $value; // filename stores the value $filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line $add = "upimg/$filename"; // upload directory path is set //echo $_FILES[images][type][$key]; // uncomment this line if you want to display the file type // echo "<br>"; // Display a line break copy($_FILES[images][tmp_name][$key], $add); // upload the file to the server chmod("$add",0777); // set permission to the file. } } and tried to merge it with my current script thus: case 'Upload Image': [color=red] while(list($key,$value) = each($_FILES['image_filename']['name'])) { if(!empty($value)){[/color] $image_name = $_POST['image_name']; $image_group = $_POST['image_group']; $location_no = $_POST['location_no']; $category_name = $_POST['category_name']; $image_info = $_POST['image_info']; $image_date_taken = $_POST['image_date_taken']; $image_tempname = $value; $today = date("Y-m-d"); $ImageDir ="img/category/"; $ImageThumb = $ImageDir . "thumbnails/"; $ImageName = $ImageDir . $image_tempname; if (move_uploaded_file($_FILES['image_filename']['tmp_name'][color=red][$key][/color], $ImageName)) { list($width, $height, $type, $attr) = getimagesize($ImageName); if ($type > 3) { echo "Sorry, but the file you uploaded was not a GIF, JPG, or " . "PNG file.<br>"; echo "Please hit your browser's 'back' button and try again."; } else { $sql = "INSERT INTO cms_images_category " . "(image_name, image_group, location_no, category_name, image_info, image_date_taken, image_date) " . "VALUES ('" . $_POST['image_name'] . "','" . $_POST['image_group'] . "','" . $_POST['location_no'] . "','" . $_POST['category_name'] . "','" . $_POST['image_info'] . "','" . $_POST['image_date_taken'] . "','" . date("Y-m-d H:i:s", time()) . "')"; mysql_query($sql, $conn) or die('Could not insert content; ' . mysql_error()); $lastpicid = mysql_insert_id(); $newfilename = $ImageDir . $lastpicid . ".jpg"; if ($type == 2) { rename($ImageName, $newfilename); } else { if ($type == 1) { $image_old = imagecreatefromgif($ImageName); } elseif ($type == 3) { $image_old = imagecreatefrompng($ImageName); } $image_jpg = imagecreatetruecolor($width, $height); imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0, $width, $height, $width, $height); imagejpeg($image_jpg, $newfilename); imagedestroy($image_old); imagedestroy($image_jpg); } $newthumbname = $ImageThumb . $lastpicid . ".jpg"; $thumb_width = $width * 0.10; $thumb_height = $height * 0.10; $largeimage = imagecreatefromjpeg($newfilename); $thumb = imagecreatetruecolor($thumb_width, $thumb_height); imagecopyresampled($thumb, $largeimage, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height); imagejpeg($thumb, $newthumbname); imagedestroy($largeimage); imagedestroy($thumb); } } [color=red] } }[/color] redirect('search.php?imageupload=yes&id=' . $lastpicid ); break; sorry that theres so much code here. but hopefully it will be clear. If anyone one could shed a bit of light on this that would be awesome. Thanks
-
I have a content management script set up so that the main body of the page can be modified by the website administrator. Basically when the administrator first arrives at the page I want them to see empty text boxes to fill the info and then submit to the database. Once the info has been stored the same page should then show the info in the text boxes and a save changes button now shows and any changes made ti the text then updates the info. What I haven't been able to acheive is to get the script to check the database to see if the info exists, and then show the empty text boxes. I know its probably a real simple thing to do.... but ..help. heres my go at it... // request info from content number '0' and show in text boxes with save changes button if ($_REQUEST['content_type_id']== 0 ) { $sql1 = "SELECT title, body, main_header, content_type_id, author_id, page_id " . "FROM cms_content " . "WHERE page_id= 'about' AND content_type_id= '0'"; $result1 = mysql_query($sql1,$conn) or die(mysql_error()); while ($row = mysql_fetch_array($result1)) { extract($row); echo ' <h2>Change main header here</h2> '; //etc etc echo ' <input type="submit" class="submit" name="action" ' . "value=\"Save Changes\">\n"; //if empty then show empty boxes and submit button. } } else if ($_REQUEST['content_type_id']<'0' ) { echo ' <h2>Add main header here</h2> '; //etc etc echo ' <input type="submit" class="submit" name="action" ' . "value=\"Submit New Content\">\n"; } // otherwise if user non-admin just show info as should be displayed } else{ $sql2 = "SELECT title, body, main_header, content_type_id, author_id, page_id " . "FROM cms_content " . "WHERE page_id= 'about' AND content_type_id= '0'"; $result2 = mysql_query($sql2,$conn) or die(mysql_error()); while ($row = mysql_fetch_array($result2)) { extract($row); //etc etc I think the issue is in the... } else if ($_REQUEST['content_type_id']<'0' ) { bit. any thoughts?
-
Ok, here it is again but just the bit pertaining to the for loop while ($row = mysql_fetch_array($results)) { extract($row); $images = $ImageThumb . $image_id . ".jpg"; $i = 0; //echo "<table> \n"; for ($y=1;$y<=1;$y++) { echo "<tr> \n"; for ($x=1;$x<=3;$x++) { echo "<td><h2>" . $image_group . "</h2></td>\n"; echo "<td><a href =\"".$ImageDir . $image_id . ".jpg\" target='top'>"; echo "<img src=\"".$images[$i++] . "\"></a></td>\n"; echo "<td><h2>" . $image_name . "</h2></td>\n"; } echo"</tr> \n"; } }
-
Hi there, I am trying to display images from a database selected and want the images to fill the page horizontally rather than vertically. The code I have got so far kind of gets there but I get the top row repeating the same image. Code is as follows: $ImageDir = "img/category/"; $ImageThumb = $ImageDir . "thumbnails/"; $getpic = "SELECT image_id, image_group, image_name, location_no " . "FROM cms_images_category " . "WHERE category_name = '" . $_GET['category'] . "'"; "ORDER BY image_group "; $results = mysql_query($getpic,$conn) or die(mysql_error()); while ($row = mysql_fetch_array($results)) { extract($row); $images = $ImageThumb . $image_id . ".jpg"; $i = 0; //echo "<table> \n"; for ($y=1;$y<=2;$y++) { echo "<tr> \n"; for ($x=1;$x<=3;$x++) { echo "<td><h2>" . $image_group . "</h2></td>\n"; echo "<td><a href =\"".$ImageDir . $image_id . ".jpg\" target='top'>"; echo "<img src=\"".$images[$i++] . "\"></a></td>\n"; echo "<td><h2>" . $image_name . "</h2></td>\n"; } echo"</tr> \n"; } } As soon as I try to add [$i++] after the $images the images disappear. take it out and get my images back but repeated three times on each row... What am I doing wrong here?
-
Client is not really internet savvy enough to cope with that. whole point of the site is to provide an easy web based platform for him to store and access all his images and for clients to access. Besides its good learning for me so might as well make it as hard as possible for myself! , Ta though.
-
Thanks for that, I'll look into it. thanks for the code tip too. Hard to know how much code to put up to be the most helpful.
-
Ta Jay6390, Have taken that advice on board. Will come back to that one. However as the client is not too keen on the zip method I'd like to at least try the multi-images. I have modified my upload script to allow up to 12 files to be selected: see below: echo "<table >"; echo "<tbody>"; echo "<tr>"; echo "<td valign='top' colspan='4'>"; echo "<h2>Please select an image or images to upload</h2>\n"; $max_no_img = 12 ; for($i=1; $i<=$max_no_img; $i++){ echo ' <input name="image_filename" type="file" size="67" id="image_filename" value="' . $imagefilename . "\">"; } echo "<br></td>"; echo "</tr>"; echo " <tr>"; echo " <td valign='top' colspan= '3'>"; echo ' <input type="submit" class="submit" name="action" ' . "value=\"Upload Image\">\n"; echo "</td>"; echo "</tr>"; echo "</tbody>"; echo "</table>"; now I just need the script that does all the work to recognise that there's more than one image being uploaded and to name them consecutively etc. I've got the images saved into the web server directory and the database just holds the information about the images. $image_name = $_POST['image_name']; $image_group = $_POST['image_group']; $location_no = $_POST['location_no']; $category_name = $_POST['category_name']; $image_info = $_POST['image_info']; $image_date_taken = $_POST['image_date_taken']; $image_tempname = $_FILES['image_filename']['name']; $today = date("Y-m-d"); $ImageDir ="img/category/"; $ImageThumb = $ImageDir . "thumbnails/"; $ImageName = $ImageDir . $image_tempname; if (move_uploaded_file($_FILES['image_filename']['tmp_name'], $ImageName)) { list($width, $height, $type, $attr) = getimagesize($ImageName); if ($type > 3) { echo "Sorry, but the file you uploaded was not a GIF, JPG, or " . "PNG file.<br>"; echo "Please hit your browser's 'back' button and try again."; } else { $sql = "INSERT INTO cms_images_category " . "(image_name, image_group, location_no, category_name, image_info, image_date_taken, image_date) " . "VALUES ('" . $_POST['image_name'] . "','" . $_POST['image_group'] . "','" . $_POST['location_no'] . "','" . $_POST['category_name'] . "','" . $_POST['image_info'] . "','" . $_POST['image_date_taken'] . "','" . date("Y-m-d H:i:s", time()) . "')"; mysql_query($sql, $conn) or die('Could not insert content; ' . mysql_error()); $lastpicid = mysql_insert_id(); $newfilename = $ImageDir . $lastpicid . ".jpg"; if ($type == 2) { rename($ImageName, $newfilename); } else { if ($type == 1) { $image_old = imagecreatefromgif($ImageName); } elseif ($type == 3) { $image_old = imagecreatefrompng($ImageName); } $image_jpg = imagecreatetruecolor($width, $height); imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0, $width, $height, $width, $height); imagejpeg($image_jpg, $newfilename); imagedestroy($image_old); imagedestroy($image_jpg); } $newthumbname = $ImageThumb . $lastpicid . ".jpg"; $thumb_width = $width * 0.10; $thumb_height = $height * 0.10; $largeimage = imagecreatefromjpeg($newfilename); $thumb = imagecreatetruecolor($thumb_width, $thumb_height); imagecopyresampled($thumb, $largeimage, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height); imagejpeg($thumb, $newthumbname); imagedestroy($largeimage); imagedestroy($thumb); } } redirect('search.php?imageupload=yes&id=' . $lastpicid ); break; Currently only the last image uploaded is saved and registered in the database. Any help would be appreciated. Oh and there is a page that deals with checking of the files after theyve been uploaded which checks for the $lastpicid which will also need to be modified... $id = $_REQUEST['id']; $getpic = mysql_query("SELECT * FROM cms_images_category WHERE image_id = '$id'") or die(mysql_error()); $rows = mysql_fetch_array($getpic); extract($rows); $image_filename = "img/category/" . $image_id . ".jpg"; list($width, $height, $type, $attr) = getimagesize($image_filename); echo " <h3>The image has been uploaded </h3> "; echo " <table><tr>"; echo " <td class ='upload' width='300' rowspan='7'>"; echo " <img src=" . $image_filename . " class =\"uploadimg\"></td>"; echo " <td class ='upload' width='150'>"; echo " <h2>Image Name</h2></td>"; echo " <td class ='upload'>"; echo ' <p><textarea class="body" name="image_info" rows="1" cols="30"> ' . htmlspecialchars($image_name) . "</textarea><br></td>\n"; echo " </tr>"; echo " <tr>"; echo " <td class ='upload'>"; echo " <h2>Image Group</h2></td>"; echo " <td class ='upload'>"; echo ' <select name="image_group" size="1" > '; echo ' <optgroup label="-------------------------------------------------">'; $query2 = "SELECT image_groups " . "FROM cms_image_group "; $results2 = mysql_query($query2,$conn) or die(mysql_error()); while ($row = mysql_fetch_array($results2)) { extract($row); echo ' <option selected value="' . $image_group . '" selected="selected">'. htmlspecialchars($row['image_groups']); } echo " </option></optgroup>\n"; echo " </select></td><br>\n"; echo " </tr>"; echo " <tr>"; echo " <td class ='upload'>"; echo " <h2>Category</h2></td>"; echo " <td class ='upload'>"; echo ' <select name="category_name" size="1" > '; echo ' <optgroup label="-------------------------------------------------">'; $query3 = "SELECT category_id, category_name " . "FROM cms_categories "; $results3 = mysql_query($query3,$conn) or die(mysql_error()); while ($row = mysql_fetch_array($results3)) { extract($row); echo ' <option selected value="' . $row['category_name'] . '" selected="selected">'. htmlspecialchars($row['category_name']); } echo " </option></optgroup>\n"; echo " </select></td><br>\n"; echo " </tr>"; echo " <tr>"; echo " <td class ='upload'>"; echo " <h2>Location No</h2></td>"; echo " <td class ='upload'>"; echo ' <p><textarea class="body" name="image_info" rows="1" cols="30"> ' . htmlspecialchars($location_no) . "</textarea><br></td>\n"; echo " </tr>"; echo " <tr>"; echo " <td class ='upload'>"; echo " <h2>Image info </h2></td>"; echo " <td class ='upload'>"; echo ' <p><textarea class="body" name="image_info" rows="5" cols="30"> ' . htmlspecialchars($image_info) . "</textarea><br></td>\n"; echo " </tr>"; echo " <tr>"; echo " <td class ='upload'>"; echo " <h2>Date image taken</h2></td>"; echo " <td class ='upload'>"; echo ' <p><textarea class="body" name="image_info" rows="1" cols="30"> ' . htmlspecialchars($image_date_taken) . "</textarea><br></td>\n"; echo " </tr>"; echo " <tr>"; echo " <td class ='upload'>"; echo " <h2>Uploaded</h2></td>"; echo " <td class ='upload'>"; echo ' <p><textarea class="body" name="image_info" rows="1" cols="30"> ' . htmlspecialchars($image_date) . "</textarea><br></td>\n"; echo " </tr>"; echo " <tr>"; echo " <td >"; echo ' <input name="id" type="hidden" value= ' . $image_id . ">\n"; echo ' <input type="submit" class="submit" name="action" ' . "value=\"Change Details\"></td>"; echo " </tr>"; echo " </table>";
-
Hi there, I am building a site where the owner needs to upload a lot of images at once. Does anyone know if it's possible to upload more than 1 image at once or even a folder full of images using the input type "file" tags? or will i need to save them as a zip first and then get the php to unzip them? if so then how do I do this? Thanks in advance
-
Hi there, Hope you don't mind but I've been trying to do this too without success. I tried kenrbnsn's version which is closer but I get the first image of each row repeated. Which seems to be what yellowepi was saying was happening originally. here's my code: echo "<table>"; echo "<tr ><td colspan = '5'>"; echo "<h1>Category: " . $category_name . " </h1>\n"; echo "</td></tr>"; $ImageDir = "img/category/"; $ImageThumb = $ImageDir . "/thumbnails/"; $getpic = "SELECT image_id, image_group, image_name, location_no " . //$getpic = "SELECT image_id " . "FROM cms_images_category " . "WHERE category_name = '" . $_GET['category'] . "'"; "ORDER BY image_group "; $results = mysql_query($getpic,$conn) or die(mysql_error()); while ($row = mysql_fetch_array($results)) { extract($row); $images = $ImageThumb . $image_id; $i = 0; //echo "<table> \n"; for ($y=1;$y<=1;$y++) { echo "<tr> \n"; for ($x=1;$x<=3;$x++) { echo "<td><h2>" . $image_group . "</h2></td>\n"; echo "<td><a href =\"".$ImageDir . $image_id . ".jpg\" target='top'>"; echo "<img src=\"".$images . ".jpg\"></a></td>\n"; echo "<td><h2>" . $image_name . "</h2></td>\n"; } echo"</tr> \n"; } } echo "<tr><td><p>Click <a href ='search.php'>here</a> to return to categories<p></td></tr></table>"; probably not very tidy code either. If someone could point me in the right direction that would be awesome. Also the amount of images in a row seems to be determined by the $x<=3, is there a way of the screen width determining this? Thanks in advance.