Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,510
  • Joined

  • Days Won

    185

Everything posted by mac_gyver

  1. the syntax you are using for the $manager variable in the WHERE clause is adding dots . before and after the value, so your WHERE clause is false and is not matching anything. you can put a php variable inside of a double quoted string. you also had single quotes around the column name in the SELECT clause, which would have literally returned the string 'manager' - $query = "SELECT manager FROM tablename WHERE manager='$manager'";
  2. @jazzman, READ the thread you are replying in. it concerns a php $_SESSION variable being overwritten.
  3. if you where doing this on paper, how would you find the distance between the last point in one row and the first point in the next row? the point of us helping you, is that you try to do this yourself first, not just to post what you want.
  4. a slightly different method to accomplish the same steps (runs faster when there are many rows) - // get Garage location for the driver ($lat,$lon) // get the route points for the driver (rows must be retrieved in the correct order) $distance = 0; // accumulate the distance // fetch the first row from the result set and get the first point ($lat1,$lon1) // calculate the distance from the Garage to the first point of the first row $distance += calc_distance($lat,$lon,$lat1,$lon1); mysql_data_seek(0); // reset to the first row of the result set // loop over the route points for the driver while($row = mysql_fetch_assoc($result)){ // assign $lat1,$lon1,$lat2,$lon2 // calculate the distance for each row (segment) in the route $distance += calc_distance($lat1,$lon1,$lat2,$lon2); } // calculate the distance from the second point of the last row to the Garage $distance += calc_distance($lat2,$lon2,$lat,$lon);
  5. here are some hints - 1) you need to write a function to calculate the distance between points so that you don't need to copy/paste/change that line of code everywhere you are using it 2) you need to define the steps that solve the problem before you can write any code to do it. see the following outline/pseudo code - // get Garage location for the driver ($lat,$lon) // get and loop over the route points for the driver (rows must be retrieved in the correct order) $first_pass = true; // flag to detect the first row inside the loop $distance = 0; // accumulate the distance while($row = mysql_fetch_assoc($result)){ // assign $lat1,$lon1,$lat2,$lon2 // calculate the distance from the Garage to the first point of the first row if($first_pass){ $distance += calc_distance($lat,$lon,$lat1,$lon1); $first_pass = false; } // calculate the distance for each row (segment) in the route $distance += calc_distance($lat1,$lon1,$lat2,$lon2); } // calculate the distance from the second point of the last row to the Garage $distance += calc_distance($lat2,$lon2,$lat,$lon);
  6. @jazzman, your reply is for some other thread.
  7. register_globals (thanks php.net) would overwrite $_SESSION['whatever'] any time you do $whatever = some value; and it will also get overwritten by a $_POST['whatever'], $_GET['whatever'], or $_COOKIE['whatever'] value.
  8. the problem is likely due to register globals or you have a session_write_close() prior to that assignment statement so it isn't actually storing to the session data and you are seeing a previous value that was stored or the code isn't successfully starting a session so that you are seeing a previous value stored in the session data. do you have php's error_reporting/display_errors both set to full on so that any session or variable reference errors will be reported? have you tried just echoing the base64_encode of a string to see what it outputs?
  9. echo $_SERVER['DOCUMENT_ROOT']; so that you can see what it is that the code should be testing for.
  10. 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.
  11. http://forums.phpfreaks.com/topic/277366-help-trying-to-create-a-dynamic-browse-by-page/?do=findComment&comment=1426892
  12. 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?
  13. @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.
  14. 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.
  15. a user or a hacker could send your script anything that can be imagined.
  16. 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.
  17. 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.
  18. 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.
  19. 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.
  20. $pdo->query() does execute the query. the code you are posting with a $pdo->execute() produces a fatal runtime error.
  21. 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.
  22. 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.
  23. 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.
  24. 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.
  25. the code you posted isn't doing that. it is trying to SELECT from comic_db.comic_db
×
×
  • 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.