
jacko_162
Members-
Posts
405 -
Joined
-
Last visited
Everything posted by jacko_162
-
i have the below code; // start of image upload $insert_id = mysql_insert_id() or die("Unable to get insert id for image name.<br>" . mysql_error()); extract($_POST); $fileArray = array(); $error=array(); $extension=array("jpeg","jpg","png","gif"); foreach($_FILES["files"]["tmp_name"] as $key=>$tmp_name) { $file_name=$_FILES["files"]["name"][$key]; $file_tmp=$_FILES["files"]["tmp_name"][$key]; $ext=pathinfo($file_name,PATHINFO_EXTENSION); if(in_array($ext,$extension)) { if(!file_exists("../images/listings/".$file_name)) { $filename=basename($file_name,$ext); $newFileName=$insert_id."_".mt_rand(1, 99999).".".$ext; move_uploaded_file($file_tmp=$_FILES["files"]["tmp_name"][$key],"../images/listings/".$newFileName); // NOW ADD NAME TO DATABASE $insertimg = "insert into $table3 (name,insert_id) values ('".$newFileName."','".$insert_id."')"; mysql_query($insertimg); array_push($fileArray, "$newFileName"); } else { $filename=basename($file_name,$ext); $newFileName=$filename.mt_rand(1, 99999).".".$ext; move_uploaded_file($file_tmp=$_FILES["files"]["tmp_name"][$key],"../images/listings/".$newFileName); // NOW ADD NAME TO DATABASE $insertimg = "insert into $table3 (name,insert_id) values ('".$newFileName."','".$insert_id."')"; mysql_query($insertimg); array_push($fileArray, "$newFileName"); } } else { $insertimg = "insert into $table3 (name,insert_id) values (' ','".$insert_id."')"; mysql_query($insertimg); array_push($error,"$file_name, "); } } // end of image upload I have managed to get this working fine, and it uploads the files and inserts data into a table. now i'm working on the edit page code and struggling to figure out how i can get this data down and display it, should i pull the data, echo the images and have some sort of IF statement to say if image exists then show a delete checkbox and if no image exists then show another file input? I'm also not sure if the add images code is the right way of doing it by adding the images to a separate line in the table or adding the array into the table for ease of use. i am not great at PHP and any help, or links to code would be great. Thanks
-
Loop results and format into columns limiting number by 8 per row
jacko_162 replied to jacko_162's topic in PHP Coding Help
ok so i worked out a JOIN query; SELECT c1.id AS parent, c1.view, c2.filename, c2.name, c2.id FROM category c1 INNER JOIN category c2 ON c1.id = c2.parent GROUP BY c2.name ORDER BY c1.id on my code on the page its indexing the category by subcategory but i cant get it to display the parent category name // pre-process the data and index it by category, creating an array of arrays with the main index being the category$data = array(); while($row = mysql_fetch_assoc($result)) { $data[$row['parent']][] = $row; } // produce the output from the data foreach($data as $category => $arr) { // Create a table with an id name of the category echo "<table width='100%' id='$category'>\n"; // Write the first row of the table - Category Title echo "<tr class='product-details'><td><span class='catTitle'>$category</span></td></tr></table><table width='100%' id='$category'>\n"; see image; -
Loop results and format into columns limiting number by 8 per row
jacko_162 replied to jacko_162's topic in PHP Coding Help
aah that makes sense, how would i join it to itself? $query = "SELECT products.id, products.category as category, products.name, products.make, images.name as imgName FROM products JOIN images ON products.id = images.insert_id GROUP BY products.id ORDER BY products.category, products.make, products.name"; i obv wont need to query the images.name and/or join it to images.insert_id -
OK so i have the following code; <!--START NAVIGATION--> <?php $categories = mysql_query("SELECT * FROM $table2 WHERE parent = '0' AND view = 'Yes' ORDER BY name ASC") or die(mysql_error()); // Select all the root categories and order them alphabetically while($category = mysql_fetch_array($categories)) // Start the loop for root categories { echo '<img src="images/arrow.gif"> <a href="catagory.php?name=' . $category['name'] . '">' . $category['name'] . '</a>'; // Display category name $subcategories = mysql_query("SELECT * FROM $table2 WHERE parent = '" . $category['id'] . "' AND view = 'yes' ORDER BY name ASC") or die(mysql_error()); // Same as the query above but this time the parent is the root category that has just been echoed echo '<br>'; while($subcategory = mysql_fetch_array($subcategories)) // Start the loop for subcategories { echo ' <img src="images/bluearrow.gif"> <a href="subcatagory.php?name=' . $category['name'] . '&sub=' . $subcategory['name'] . '"><em>' . $subcategory['name'] . '</em></a><br>'; // Display subcategory name } } ?> <!--END NAVIGATION--> and it displays a nice list of my category and sub category like so; No i need to keep the category in the same place but where it lists the sub category i want each one to sit in a <div></div> and run in columns to a maximum of 8 before starting a new row, i have done this before but seen as it has 2 main query its confusing the crap out of me. i know this should be in PDO but unfortunately i just have to fix the site up in the next few days for a friend and until then i'm not going to start editing the whole site to use PDO. can anyone help me or point me in a good direction of existing code and where is best to put it. thank you
-
as above, i am trying to do a small art project but it will mean i need to get a whole load of video thumbnails for certain youtube channels. after searching the internet i come across a lot of PHP related functions but i'm not sure where to go. basically can it be done with PHP/feeds/API etc.. i need to display a PHP web page that just echo's a certain youtubers video thumbnails from say the past 12 months in an OK size (small/medium thumbnail) and then i can manually right click and save each one? any help or even code on the matter would be lovely. or even links to web pages that can do this for me? i'm not even sure it can be done.
-
looping results from query and limit amount per row
jacko_162 replied to jacko_162's topic in PHP Coding Help
aaah i fixed it, i must of copy+paste the wrong code and it put "catagory" again..... once changed to "category" it worked fine <Derp> <Derp> marking topic now SOLVED -
looping results from query and limit amount per row
jacko_162 replied to jacko_162's topic in PHP Coding Help
i changed: $data = array(); foreach($result as $row) to: $data = array(); while($row = mysql_fetch_assoc($result)) and now i'm getting some data being echo'd but its not formatting in rows of 5, however i have no idea what to change the other foreach() loops to for it to work. here is what i get on page after i changed the above while(); looks like the first chunk is displayed but its not showing the next chunk on a new line underneath?? -
looping results from query and limit amount per row
jacko_162 replied to jacko_162's topic in PHP Coding Help
ok thats sorted my results out in phpmyadmin when i run the query, but when i run the code on my server with the code above i just get a blank page with nothing being echo'd -
looping results from query and limit amount per row
jacko_162 replied to jacko_162's topic in PHP Coding Help
THANK YOU FOR THE CODE, i only just realised the "catagory" mistake. its actually not catagory its "category". here are the 2x tables; relationship between the two tables are products.id and images.insert_id Images: http://clip2net.com/clip/m513573/4d3b6-clip-98kb.png?nocache=1 Products: http://clip2net.com/clip/m513573/4b6a0-clip-38kb.jpg?nocache=1 so i tried your code and nothing is getting displayed, so for the time being i edited out the PDO and converted to depreciated code, as for now i'm just trying to code the last page and a few bits, then i can edit the whole site and change/learn to PDO. here is the code i have now which i edited it slightly. $items_per_row = 5; // number of items per output row $query = "SELECT products.id, products.category as category, products.name, products.make, images.name as imgName FROM products JOIN images ON products.id = images.insert_id ORDER BY products.category, products.make, products.name"; // execute query $result = mysql_query($query); // pre-process the data and index it by category, creating an array of arrays with the main index being the category $data = array(); foreach($result as $row) { $data[$row['category']][] = $row; } // produce the output from the data foreach($data as $category => $arr) { // Create a table with an id name of the category echo "<table width='100%' id='$category'>\n"; // Write the first row of the table - Category Title echo "<tr><td><span class='catTitle'>$category</span></td></tr>\n"; // output the rows of data $chunks = array_chunk($arr, $items_per_row); foreach($chunks as $chunk) { echo "<tr>"; // start a new row foreach($chunk as $row) { // Write new <td> in table with the data of the title echo '<td width="20%" class="cellPadd"><a href="product.php?id=' . $row['id'] . '"><div class="latest"><div class="latestTop">'; echo "<img class='latestImg' src='images/listings/" . $row['imgName'] . "' border='0' width='100%' />"; echo '</div><div class="latestBottom">'; echo $row["make"]; echo $row["name"]; echo "</div></div></a></td>\n"; } // complete a partial row $count = count($chunk); if($count < $items_per_row) { echo str_repeat("<td> </td>\n", $items_per_row - $count); } echo "</tr>\n"; // end the row } echo "</table>"; // end the table } i tested the SQL query and it gave me this; so its pulling data i just need to LIMIT the 'id' to only show 1 as some products can contain upto 4 images per id. can you check whys it not echo anything? -
Trying to show data from a query and echo the results and grouping them by category after printing the category name. So far all is working as intended, however i'm trying to incorporate a count limit so it only echo x5 <td></td> before making a new <tr> row here is my current code; <?php $select = "SELECT * FROM `products` ORDER BY `catagory`"; $result = mysql_query($select); $current_cat = null; $last_cat = null; while ($rows = mysql_fetch_array($result)) { if ($current_cat == null) { // Create a table with an id name of the first table echo "<table width='100% id='" . $rows["catagory"] . "'>"; // Write the first row of the table - Category Title echo "<tr><td><span class='catTitle'>" . $rows["catagory"] . "</span></td></tr><tr>"; } // Set the $current_cat to current loop category value $current_cat = $rows["catagory"]; $getID = $rows['id']; if ($last_cat != null) { if ($current_cat != $last_cat) { // Close table from previous $current_cat echo "</table>"; // Create new table with id name of the category echo "<table width='100%' id='" . $rows["catagory"] . "'>"; // Write the first row of the table - Category Title echo "<tr><td><span class='catTitle'>" . $rows["catagory"] . "</span></td></tr><tr>"; } } //Fetch Image name from "IMAGES" table that corresponds to the product ID $thumbnail_query = mysql_query("SELECT name FROM $table3 WHERE insert_id = $getID LIMIT 1") or die (mysql_error()); //Fetch Results while($data = mysql_fetch_array($thumbnail_query)) { $imgName = $data['name']; } // Write new <td> in table with the data of the title echo '<td width="20%" class="cellPadd"><a href="product.php?id=' . $getID . '"><div class="latest"><div class="latestTop">'; echo "<img class='latestImg' src='images/listings/" . $imgName . "' border='0' width='100%' />"; echo '</div><div class="latestBottom">'; echo $rows["make"]; echo $rows["name"]; echo '</div></div></a></td>'; // set the $last_cat to the value of $current_cat at the end of the loop $last_cat = $current_cat; } echo "</tr>"; // Close the last table after while loop ends echo "</table>"; ?> and i am trying to incorporate; $cnt = 0; // IF COUNT IS MORE THAN 5 MAKE A NEW ROW if($cnt % 5 == 0) echo "CODE HERE FOR NEW ROW!"; $cnt++; can anyone help me as its giving me a headache now. ;( Many thanks