Jump to content

genista

Members
  • Posts

    149
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

genista's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. 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
  2. Thanks, so if that is not the issue, what is causing the results to start again once the user gets to the end?
  3. 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
  4. Thanks, both responses have helped and solved the issue. G
  5. 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
  6. Doh! Spot on, thanks for pointing that out
  7. 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
  8. Thanks, and you are right. Looking at your fiddle it seems I need to increment a value for each panel button within each box in php to have this work individually rather than for all boxes? G
  9. All, I am taking the output for every title in my Database and displaying it in a box. Within that box I am providing the opportunity to open another box with further content inside. The problem with the code below is that when you click on the expand button it expands in all the boxes, not just the one you are clicking in. I don't understand why this is happening when everything else is ok - any fixes and explanations are greatly appreciated: // GOING THROUGH THE DATA if($result->num_rows > 0) { //echo "<hr />"; while($fetch=mysqli_fetch_array($result)) { $title=$fetch['title']; $feed_rss=$fetch['url']; $content_id=$fetch['content_id']; $source_image=$fetch['source_image']; $item_id = $fetch['item_id']; $item_title = $fetch['item_title']; $item_date = $fetch['fetch_date']; $item_description = $fetch['item_description']; $item_url = $fetch['item_url']; ///////////////////////////////////////////////////////////////////////////////// // ?> <div class="box col5"> <?php $query_string = "cid={$content_id}&t={$item_id}&item_title={$item_title}"; $url_query_string = "http://www.disciply.com/article/index.php?" . $query_string; /*Start of dynamic content open*/ echo "<p>$title</p>"; echo "<img src=$source_image />"; echo "<p>item_url = $item_url</p>"; ?> <div class="panel_button" style="display: visible;"><img src="../images/expand.png" alt="expand"/> <a href="#"><?php echo $item_title; ?></a></div> <div class="panel_button" id="hide_button" style="display: none;"><img src="../images/collapse.png" alt="collapse" /> <a href="#">Hide</a> <object type="text/html" data='<?php echo $item_url;?>' width="100%" height="800px" style="overflow:auto;border:5px ridge blue"> </object> </div> </div>
  10. I guess I need to read through the item in the feed and then retrieve the image, I was hoping to do it this way but never mind. Thanks, g
  11. All, I have most of the info I want from rss feeds, but I cannot seem to get anything on the image, here is the full code I am testing: <?php libxml_use_internal_errors(true); $RSS_DOC = simpleXML_load_file('http://rss.cnn.com/rss/cnn_topstories.rss'); if (!$RSS_DOC) { //Errors } else{ //setup rss feed } $RSSimagedetails = $RSS_DOC->channel->image; $RSSitem = $RSS_DOC->channel->item[0]; $item_id = md5($RSSitem->title); //$fetch_date = date("Y-m-j G:i:s"); //NOTE: we don't use a DB SQL function so its database independant $item_title = $RSSitem->title; //$item_description = $RSSitem->description; $item_date = date("Y-m-j G:i:s", strtotime($RSSitem->pubDate)); $item_url = $RSSitem->link; //$item_image = $RSSitem->getElementsByTagName('image')->item(0)->getAttribute('url'); $item_image_src = $RSS_DOC->channel->image->src; $item_image_link = $RSS_DOC->channel->image->link; $Pubdate = $RSSitem->pubDate; echo "<p>item_id = $item_id</p>"; echo "<p>item_title =$item_title</p>"; echo "<p>item_url = $item_url</p>"; echo "<p>iem_image_src = $item_image_src</p>"; echo "<p>item_image_link = $item_image_link</p>"; echo "<img src=\"" . (string)$RSSitem->enclosure['url'][0] . "\">"; None of the image items are returning anything, any ideas on the best way to pull this out - specifically the url of the image? Thanks, G
  12. Thanks for that, I think I have it solved from this. G
  13. Thanks all, Barand: Apologies, the date format was just for putting over what I am trying to do, the formats are ok in the database. Gristoi: I will remove the second select, as for the data being on both sides, the content_id is where I am making the join. Other than that the data is different so I am guessing I need two queries - one to pull the author, then once I have that find the latest post for each author?
  14. All, I am trying to join two tables, one contains information about an author, the other their posts. I want to retrieve the latest posts from the posts table. As an example: Table: 'Detail' content_id, title, approved 1, fred, y 2, tommy, y Table: 'posts' content_id, item_title, item_date 1, blah 1, 19/02/2014 2, blah 2, 19/02/2014 1, blah 3, 17/02/2014 2, blah 4, 17/02/2014 I would expect to see from my query below: content_id, title, item_date 1, blah 1, 19/02/2014 2, blah 2, 19/02/2014 This query does not retrieve any results: SELECT t1.content_id, t1.title, t1.source_image, t1.url, t1.approved FROM detail AS t1 INNER JOIN ( SELECT content_id, item_id, item_title, max( item_date ) FROM posts GROUP BY content_id ) AS t2 ON t1.content_id = t2.content_id I have split them out into two queries for testing: SELECT content_id, title, source_image, url, approved FROM content_detail This retrieves all data from that table as expected. The following query just returns the first row instead of all of them: SELECT content_id, item_id, item_title, max( item_date ) FROM posts I want to avoid splitting these queries into two, ie get the author detail then for each returning their top Post so any help on how to do this with just one would be great. 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.