Jump to content

jacko_162

Members
  • Posts

    405
  • Joined

  • Last visited

About jacko_162

  • Birthday 03/30/1984

Contact Methods

  • Website URL
    http://www.real-creative.co.uk

Profile Information

  • Gender
    Male
  • Location
    Staffordshire, United Kingdom

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

jacko_162's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

  1. 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
  2. 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;
  3. 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
  4. 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
  5. 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.
  6. 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
  7. 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??
  8. 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
  9. 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?
  10. 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
  11. ok so i did this; <?php $pageNr = $page; // Get Current Page Number $from = $pageNr * $num_rec_per_page - 9; // 3 * 10 = 30 $to = $from + 9; // 30 + 9 = 40 // ECHO results Statements echo "Showing Results " .$from. " to " .$to. " "; ?> which works, but the last page may not be equal to exactly 10, for example 47 total results on page 4 it will only show 7 rows, so i did an if statement to check if its the last page and assign different math to the variable. how do i work out the last number?? <?php$pageNr = $page; // Get Current Page Number $from = $pageNr * $num_rec_per_page - 9; // 3 * 10 = 30 //check if last page and change variables if (isset($_GET['page']) && $_GET['page'] == $total_pages) { $to = $count / $num_rec_per_page; } else { $to = $from + 9; } // ECHO results Statements echo "Showing Results " .$from. " to " .$to. " "; ?>
  12. i have built pages that paginate with 10 rows per page (some pages show more but for the moment i want to focus on this particular page) //Define Some Options for Pagination $num_rec_per_page=10; if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * $num_rec_per_page; $results = mysql_query("SELECT * FROM `ecmt_memberlist` WHERE toonCategory='Capital' AND oldMember = 0 ORDER BY CONCAT(MainToon, Name) LIMIT $start_from, $num_rec_per_page") or die(mysql_error()); $results_array = array(); while ($row = mysql_fetch_array($results)) { $results_array[$row['characterID']] = $row; } The above sets the variables for the pagination and below the results are echo with 10 rows per page then i show the pagination links: <?php $sql = "SELECT * FROM `ecmt_memberlist` WHERE toonCategory='Capital' AND oldMember = 0 ORDER BY CONCAT(MainToon, Name)"; $rs_result = mysql_query($sql); //run the query $total_records = mysql_num_rows($rs_result); //count number of records $total_pages = ceil($total_records / $num_rec_per_page); ?> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="center"><div style="width:100%; text-align:center;"> <ul class="pagination"> <li class="selected"> <?php echo "<a href='capitalmember.php?page=1'>".'«'."</a> ";?> </li> <? for ($i=1; $i<=$total_pages; $i++) { echo "<li><a href='capitalmember.php?page=".$i."'>".$i."</a></li> "; }; ?> <li class="selected"> <? echo "<a href='capitalmember.php?page=$total_pages'>".'»'."</a> "; // Goto last page ?></li> </ul></div> <?php $pageNr = $page; // Get Current Page Number $from = $pageNr * $rowsPerPage; // 3 * 10 = 30 // 3 * 10 = 30 $to = $from + $rowsPerPage; // 30 + 10 = 40 echo $pageNr; /* Result: From page 30 to 40 */ ?></td> </tr> </table> this works great and shows me 10 results per page, what i need to work out and work on next is: echo the number of results above the records (for example: "showing records 1 to 10" and then on page 2 "showing records 11 to 21" and page 3 "showing records 22 to 32" how can i work out the maths for this echo? i was thinking along the lines of; <?php $pageNr = $page; // Gets Current Page Number $from = $pageNr * $rowsPerPage; // 3 * 10 = 30 $to = $from + $rowsPerPage; // 30 + 10 = 40 // Now Show Results echo $from; // Echo from echo $to // Echo to ?> but i'm still working on this.. then i need to look at shortening the amount of page links on the page if for example i have 500 records it shows me links 1 to 50 and eats up the page.... Appreciate any help and light onto my problems. Many thanks
  13. I have a Login page which i want to check if the user details (username, password and activation) are valid then redirect user dependent on his/her "accessLevel" (admin, member and none) Admin will be directed to "index.php" Member will be directed to "tasks.php" and none will be redirected to "notActive.php" here is my current code which half works; <?php include ('connect.php'); if(isset($_POST['submit'])) { // Initialize a session: session_start(); // Define $username and $password $username=$_POST['username']; $password=$_POST['password']; // To protect MySQL injection $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $sql="SELECT * FROM ecmt_members WHERE username='$username' and password='$password' AND Activation IS NULL"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $username and $password, table row must be 1 row if($count==1){ // Register $username, $password and redirect to file "index.php" $role = mysql_fetch_array($result); $_SESSION['username']= $username; $_SESSION['password']= $password; //$_SESSION['role']= $role['accessLevel']; if($role['accessLevel'] == "admin"){ $_SESSION['adminuser']=$role['accessLevel']; header("location:index.php"); exit(); } elseif($role['accessLevel'] == "member"){ $_SESSION['user']=$role['accessLevel']; header("location:tasks.php"); exit(); } else { echo "Error: Username, Password or Access Level incorrect! Go Home, you're Drunk!!!"; } } } // End of the main Submit conditional. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Login Form</title> <!-- jQUERY --> <script src="//code.jquery.com/jquery-latest.js"></script> <!-- Add Main CSS --> <link rel="stylesheet" type="text/css" href="../tool/css/main.css"> <!-- Font-Awesome --> <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"> <style> body { background: url(../tool/images/bg1.jpg) no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; } .exactCenter { width:auto; height:auto; position: fixed; top: 50%; left: 50%; margin-top: -200px; ; } </style> </head> <body> <div class="exactCenter"> <div id="login-container"> <img src="../tool/images/bigLogo.png" /><br /> <form action="login.php" method="post" class="form"> <fieldset class="group"> <input class="input" type="text" id="username" name="username" size="25" placeholder="username"/> <img src="../tool/images/spacer.png" width="5" height="5" /> <input class="input" type="password" id="password" name="password" size="25" placeholder="password"/> <img src="../tool/images/spacer.png" width="5" height="5" /> </fieldset> <input type="hidden" name="formsubmitted" value="TRUE" /> <button type="submit" name="submit" class="btn btn-blue" ><i class="fa fa-unlock-alt"></i> Login</button> <img src="../tool/images/spacer.png" width="5" height="5" /> <a href="Register.php"><button type="button" class="btn btn-green" ><i class="fa fa-hand-o-up"></i> Register</button></a> </form> </div></div> </body> </html> When i test it with admin login credentials i get the page refresh again without error, when i login with member credentials it shows tasks.php and when i try to log in with unactivated account "acivation column is not NULL" i get a page refresh also with no error. Can someone help me make it work for each role and perhaps have some sort of error reporting depending on error. im pulling my hair out here and this is the first time i have worked with login conditions, and im VERY confused.
  14. I have collected some data from .xml api's and I need to manipulate it in a way to display something specific. not my strongest point when it comes to maths & date data. so ultimately I need it to echo something like the following: "3 Days 4 Hours Remaining" or "14 Hours Remaining" (if below 24 hours!!!) I use the following to pull my variables and to test by echo results. <?php // Calculate total Fuel blocks $itemID = $record['itemID']; $result = mysql_query("SELECT * FROM `ecmt_poslistdetails` WHERE itemID = '$itemID' AND (typeID='4051' OR typeID='4247' OR typeID='4246' OR typeID='4312')"); $row = mysql_fetch_array($result); $fuelQty = $row[quantity]; echo $fuelQty; ?> <br /> <?php // Calculate total Fuel blocks used per hour $typeID = $record['typeID']; $result = mysql_query("SELECT * FROM `ecmt_posfuel` WHERE typeID = $typeID"); $row = mysql_fetch_array($result); $fuelUse = $row['fuel']; echo $fuelUse; ?> this gives me: $fuelQty & $fuelUse so for instance if fuel quantity is: 18480 and $fuelUse is: 40 the fuel used is 40x per hour and time remaining would be 462x Hours remaining but I want it to display: 19 Days 6 Hours Remaining how can I achieve this format?
×
×
  • 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.