Jump to content

plugnz

Members
  • Posts

    21
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

plugnz's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. aw read about that GROUP BY but didn't quite get it! Thanks heaps.
  2. 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....
  3. 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
  4. 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
  5. 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.
  6. 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
  7. 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???
  8. Hi sorry, error I'm getting is :
  9. 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
  10. 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?
  11. 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"; } }
  12. 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?
  13. 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.
  14. 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.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.