Jump to content

genista

Members
  • Posts

    149
  • Joined

  • Last visited

Everything posted by genista

  1. Spot on thank you so much!
  2. I have a dropdown where the options are pulled from a database into an array for display. This works fine, what I am trying to understand is how to incorporate showing the selection a user has made previously that was written to a table. I understand how to do this without an array (by checking if it is set and then pushing selected to display it) but this I am struggling with. I have a value pulled from a select statement, if that is set I want to mark the right value in the dropdown as selected. This below is not displaying that, it just shows the first option in the drop down. What am I missing? $statid is set from a select statement earlier in the script, printing it displays the value no problem result_stat_query = $DB_con->prepare('SELECT statid, stat_name FROM stats ORDER BY statid'); $result_stat_query->setFetchMode(PDO::FETCH_ASSOC); $result_stat_query->execute(); $row_stat = $result_stat_query->fetchAll(); echo "<select name='stat_id' onchange='filterContent(this);'>"; foreach ($row_stat as $r) { if (isset($statid)){ echo "<p>statid=$statid</p>"; echo '<option value='.$statid.'>'.$r['stat_name'].'</option>'; } else{ // first run echo '<option value="'.$r['statid'].'">'.$r['stat_name'].'</option>'; } } echo "</select>"; Thanks, G
  3. Thanks, so if that is not the issue, what is causing the results to start again once the user gets to the end?
  4. Hi, I have an infinite scroll scipt that is pulling data and displaying it just fine. However, I am finding that when you scroll down the data pull starts again at the beginning. Right now I have 8 rows for testing in the database to make it easy. My control to get the next data set does not seem to be working otherwise it would go to the next set of results? PHP Code: //item per page $limit = 5; $page =(int)(!isset($_GET['p']))?1: $_GET['p']; // sql query $sqlContent="SELECT make, model, year, carid FROM cars"; //Query start point $start =($page * $limit)- $limit; $resContent=$DB_con->query($sqlContent); $rows_returned= $resContent->rowCount();//->fetchColumn(); // query for page navigation if( $rows_returned > ($page * $limit)){ $next =++$page; } $sqlContent = $sqlContent ." LIMIT $start, $limit"; $finalContent = $DB_con->query($sqlContent); if($finalContent === false) { trigger_error('Error: ' . $DB_con->error, E_USER_ERROR); } else { $rows_returned= $finalContent->rowCount();//->fetchColumn(); } ?> then display the results: PHP Code: PHP Code: <?php while($rowContent = $finalContent->fetch()) { $year = $rowContent['year']; $make = $rowContent['make']; $model = $rowContent['model']; ?> <div class="row"> <div class="ride"><?php echo "$year $make $model"; ?></div> </div> <?php } ?> </div> </div> <!--page navigation--> <?php if(isset($next)):?> <div class="nav"> <a href='index.php?p=<?php echo $next?>'>Next</a> </div> <?php endif ?> </div> When I print some of the variables, this is what I get: start=0 rows_returned = 5 next=2 page=2 Page 2 starts from the beginning, shouldn't that be 1 and then increment? Thanks, G
  5. Thanks, both responses have helped and solved the issue. G
  6. Hi, I am using GET to receive a variable from a url and then selecting from the DB where I find a match on that value. The problem, which I have never seen before the error tells me that the value is being used to find the column name: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'car' Here is the code, the get value is car - why is it doing this?! $type = $_GET['type']; $userid = $_SESSION['user_session']; //item per page$limit = 5; $page = filter_input(INPUT_GET, 'p', FILTER_VALIDATE_INT, array( 'options' => array('min_range' => 1, 'default' => 1))); $sqlContent="SELECT make, model, year, rideid FROM ride1 WHERE type = $type"; Thanks, G
  7. Doh! Spot on, thanks for pointing that out
  8. Hi, I am working my way through an image upload process and writing the file name to the database, which is where I am getting stuck. I am getting the error: PHP Catchable fatal error: Object of class PDO could not be converted to string on this piece of code (taken from the larger piece below): $stmt->$DB_con->prepare($query); Here is the full code from the script: userid = $_SESSION['user_session']; $stmt = $DB_con->prepare("SELECT rideid, userid, make, model, image1 FROM ride1 WHERE userid= :userid"); $stmt->execute(array(":userid"=>$userid)); $userRow=$stmt->fetch(PDO::FETCH_ASSOC); $image1 = $userRow['image1']; $rideid = $userRow['rideid']; if( ( $image1 == '' ) ) { $ds = DIRECTORY_SEPARATOR; //1 $storeFolder = '../ride_images'; //2 if (!empty($_FILES)) { $tempFile = $_FILES['file']['tmp_name']; //3 $targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds; //4 $image1 = $targetPath.$userid.$rideid. $_FILES['file']['name']; //5 move_uploaded_file($tempFile,$image1); //6 $query ="UPDATE ride1 SET image1= :image1 WHERE rideid= :rideid"; $stmt->$DB_con->prepare($query); /* However, you pull your data in, I just used $image1 & $rideid for the example */ $stmt->execute([ ':image1' => $image1, ':rideid' => $rideid ]); Any help you can give would be much appreciated. Thanks, G
×
×
  • 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.