Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,450
  • Joined

  • Days Won

    175

Everything posted by mac_gyver

  1. echo $_SERVER['DOCUMENT_ROOT']; so that you can see what it is that the code should be testing for.
  2. there's a whole section for this in the mysql documentation - http://dev.mysql.com/doc/refman/5.5/en/example-maximum-column-group-row.html does the box column actually the number name, one, two, ...? if it was the numerical number 1,2,3... it would be easier to order the output. however you cause use ORDER BY FIELD(box, 'one', 'two', ...) to order by the number name.
  3. http://forums.phpfreaks.com/topic/277366-help-trying-to-create-a-dynamic-browse-by-page/?do=findComment&comment=1426892
  4. what you do see when you do a 'view source' of the page in your browser, both before you submit the form and after you submit the form?
  5. @jazzman, the query (less the order by and limit added from what the first post in this thread was doing) is what you posted and since it is joining the cardid to its image, a one-to-one relationship, its the join you would need to use to get the image that corresponds to the row in the cardid table.
  6. i don't have the slightest idea what that means? the query and the logic in the code can be modified to do anything you want. the only thing i basically did was to make sure it would run or it would tell you why it didn't.
  7. a user or a hacker could send your script anything that can be imagined.
  8. the following code should work and if it doesn't it contains enough error checking logic to tell you why it didn't. the main html page - try { $pdo = new PDO('mysql:host=localhost;dbname=database','admin','root'); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } $query = "SELECT i.img, i.cid FROM images i INNER JOIN cardId as c ON i.cid = c.id WHERE c.status = 1 ORDER BY c.id ASC LIMIT 10"; if(!$stmt = $pdo->prepare($query)){ // prepare failed echo "<pre>Prepare failed:\n"; print_r($pdo->errorInfo()); echo "</pre>"; } else { if(!$stmt->execute()){ // execute failed echo "<pre>Execute failed:\n"; print_r($stmt->errorInfo()); echo "</pre>"; } else { $result = $stmt->fetchAll(PDO::FETCH_ASSOC); if(count($result) == 0){ echo "Query matched zero rows."; } else { //echo '<pre>', print_r($result,true),'</pre>'; // take a look at the result foreach($result as $image){ $img = imagecreatefromstring($image['img']); $height = imagesy($img); $width = imagesx($img); if($height > 100 OR $width > 120){ echo "<img src='noimage.png' alt='' />"; } else { echo "<img src='images.php?cid={$image['cid']}' alt='' />"; } } } } } the images.php file, needed to dynamically output the image that is stored in the database (the amount of code needed to do this is just one of the reasons NOT to store files in a database) - $cid = isset($_GET['cid']) ? (int)$_GET['cid'] : 0; if($cid < 1){ die; // do nothing for impossible cid values } try { $pdo = new PDO('mysql:host=localhost;dbname=database','admin','root'); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } $query = "SELECT img,type FROM images WHERE cid = :cid"; if(!$stmt = $pdo->prepare($query)){ // prepare failed echo "<pre>Prepare failed:\n"; print_r($pdo->errorInfo()); echo "</pre>"; } else { $stmt->bindParam('cid', $cid, PDO::PARAM_INT); // this can fail and return a false, but i couldn't find an (easy) condition to cause it to fail if(!$stmt->execute()){ // execute failed echo "<pre>Execute failed:\n"; print_r($stmt->errorInfo()); echo "</pre>"; } else { if($result = $stmt->fetch(PDO::FETCH_ASSOC)){ // should always match the one row given by cid //echo '<pre>', print_r($result,true),'</pre>'; // take a look at the result header("Content-Type: {$result['type']}"); echo $result['img']; } } } the above code ASSUMES/requires that your images database table has a type column that holds the content type for the image, such as image/jpeg for a jpg/jpeg image.
  9. it's not supposed to work, but does, with named placeholder if the : is not there. i would suggest that leaving it out may cause your code to break at any version change.
  10. there's so much wrong with this thread, i don't know where to begin. the current problem is that the bind_parm() statement is using the wrong syntax for the placeholder. it would need to be ':cid'. but since you are actually trying to retrieve the first 10 rows with ascending ids, you wouldn't need to match any cid in the query at the point of outputting the <img > tags on a web page. you will need to match individual cid's when you actually output the image to the browser (read on to find out what this means.) back to the stated task and the first posted code. you are trying to output x number of images on a web page. to do that you must output an <img src=' ... '> tag for each image. to determine the image dimensions, since you apparently didn't store them with the image data, you must retrieve all the matching image data and use GD to create each image to find it's dimensions. (as a side note, you cannot output the image data in your html page, so you must repeat this process in a separate .php script to output each stored image, one at a time when the browser requests each image.) this will require a huge amount of processing each time your page gets requested. if it is an option, you should add height and width columns to the images table and populate them with the dimensions of each stored image.
  11. your need to set session.gc_maxlifetime to a longer value. you must do this before every session_start() statement. if you are on a shared web server, you must also make you own folder for the session data files and set your session.save_path setting to point to the folder.
  12. $pdo->query() does execute the query. the code you are posting with a $pdo->execute() produces a fatal runtime error.
  13. you can no longer reference object properties using array syntax. you must either correctly reference the property - $lang_data->lang_id or you must cast the object to an array.
  14. the php.net documentation contains version migration summaries in an appendix. reading those will bring you up to date on what has changed and what has been depreciated or removed at each major version so that you can identify information that is out of date.
  15. all text and textarea form fields are set any time the form is submitted, even if they are empty. only checkbox/radiobuttons will not be set when they are not selected. what makes you think your variable from a form will/should be a null? your form processing code should test if a form has been submitted, then all the code within the form processing code doesn't need to individually test if text/textarea fields are set. they will be.
  16. all the places $result->ProspectName is used must be replaced with $theresult. the single quote in the $result->ProspectName value is breaking the javascript syntax.
  17. the code you posted isn't doing that. it is trying to SELECT from comic_db.comic_db
  18. what have you tried? just posting your query again shows nothing. you either need to make sure you are suppling a value for every column in the table (your existing query method) or you must list the columns you are supplying values for (the suggested query method.) since we don't know what the original columns were, what column(s) you added, where in the existing column order you added it(them), or even which of the values shown are for the added column(s), we cannot help you with this straight-forward task. this is something that you need to do. something tells me that you added column(s) to the table but didn't add any corresponding values to the query. that's only about 1/10 the amount of work needed to add a field of data. btw - the link in the first post in this thread that you copy/pasted from the other forum you posted this in is broken since only the visible text was copy/pasted.
  19. ORDER BY lb DESC, oz DESC LIMIT 4
  20. your code is all over the place with copy/pasted logic that isn't doing anything toward your goal. i cleaned it up for you and arranged it in a logical/necessary order. forming your multi keyword search is still up to you, but you do it ONCE in the logic where indicated - <?php require 'config.php'; mysql_connect ($dbhost, $dbusername, $dbuserpass); mysql_select_db($dbname) or die('Cannot select database'); // process any search term $search = ''; // default to an empty string if(isset($_GET['search'])){ $search = trim($_GET['search']); $search = preg_replace('/\s+/', ' ', $search); // replace multiple white-space with one space } // produce the where condition here... // ... your code that you need to figure out for multiple keywords goes here (this is the only place you need to have any keyword logic) // fake a where_condition for testing - i.e. works when one keyword is entered if($search != ''){ $where_condition = "title like '%$search%'"; } else { $where_condition = '1=1'; } // all the following code is basic pagination logic and it doesn't need any logic added to it to search for multiple keywords $table_name = 'your_table'; $rows_per_page = 20; // get and calculate the total number of pages $query = "SELECT COUNT(*) FROM $table_name WHERE $where_condition"; $result = mysql_query($query); $row = mysql_fetch_row($result); $total_records = $row[0]; $total_pages = ceil($total_records / $rows_per_page); // get and limit the requested page number if (isset($_GET["page"])){ $page = (int)$_GET["page"]; } else { $page=1; // not set, default to 1 } if($page < 1){ $page = 1; } if($total_pages > 0 && $page > $total_pages){ $page = $total_pages; } // produce and run the main query $start_from = ($page-1) * $rows_per_page; $query = "SELECT * FROM $table_name WHERE $where_condition ORDER BY Title ASC LIMIT $start_from, $rows_per_page"; $result = mysql_query($query); $count = mysql_num_rows($result); if($count <= 0){ // no matching rows echo "<center><b><FONT COLOR=\"red\">Your query returned no results from the database.</font></b><br /></center>"; } else { // one or more matching row echo "<TABLE border=1><tr><td><b>Link</b></td><td><b>Gravity</b></td><td><b>InitialEarningsPerSale</b></td><td><b>AverageEarningsPerSale</b></td><td><b>ActivateDate</b></td></TR><TR>"; while($row = mysql_fetch_array($result)){ echo "<tr><td>".$row['Link']."</td><td>".$row['Gravity']."</td><td>".$row['InitialEarningsPerSale']."</td><td>".$row['AverageEarningsPerSale']."</td><td>".$row['ActivateDate']."</td></tr>"; } echo "</table>"; } // produce the pagination links if($total_pages > 1){ // no point if there's only one page for ($i=1; $i<=$total_pages; $i++) { echo "<a href='?search=$search&page=".$i."'>".$i."</a> "; } } ?>
  21. you were explicitly told that you need to build a correctly formatted WHERE condition in a variable so that you can use it in both queries (you could actually use a portion of quickoldcar's code to do that.) both queries must match the same rows for this to work. until you can produce the correct queries from your search input value, you won't be able to get your code to work. programming involves breaking down a task into the steps needed to complete that task. just work on producing the correct WHERE condition in a variable and you must do this in your code before you make or run either one of the queries.
  22. when you don't list the column names in the INSERT query, you must supply a value for every column in the table and they must be in the same order that the columns are defined in the table. it is always best to list the column names - INSERT INTO your_table (list of columns) VALUES (list of values) you only need to list the column names you are inserting values for (non-listed columns get their default values/auto increment value) and only the order of the listed columns and listed data must match each other (you don't need to know what the actual order is in the table definition.) for a complex query (with more than a few columns/values) it is easier to see what the query is by using the sprintf() to build the query in a php variable - $query = sprintf("INSERT INTO your_table (col1,col2,col3,...) VALUES ('%s',%d,'%s', ...)", $some_string_value, $some_integer_value, $someother_string_value); you can then echo the $query variable to see exactly what the query statement is.
  23. it causes the username column to be treated as a number and any username that doesn't start with a numerical character will be a zero value and will be matched.
  24. by subtracting a zero, the value is converted to a number.
  25. by default, the mysql trim() function only removes spaces. you would need to supply the optional remstr parameter to get it to trim anything else.
×
×
  • 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.