Jump to content

genista

Members
  • Posts

    149
  • Joined

  • Last visited

Everything posted by genista

  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
  15. Thanks guys, spot on - I have taken note of your comments on the for each and changed accordingly. G
  16. Hi all, I have a most strange problem, and I am not sure if it is because of a long overdue move to mysqli from mysql or something else that is ludicrously simply wrong with what I am doing. I am doing a select on name from users where the userid = the sessions userid. From there I want to set the $personsname variable from the name column - simple. The query below runs fine without error and I can print out the name, but what I cannot do is set the variable up: $query1 = "SELECT name FROM `users` WHERE `userid`=$userid"; $result = $mysqli->query($query1) or die($mysqli->error.__LINE__); // GOING THROUGH THE DATA if($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo stripslashes($row['name']); $personsname=stripslashes ($row['$name']); = FRED BLOGS - correct echo "<p>name=$personsname</p>"; = EMPTY?!?!?!?! I am sure the answer is embarrassingly simple, but I just cant get my head around this.. Thanks, G
  17. Guys, thank you very much, realised my mistake and all is now working!
  18. Thanks, I have implemented your changes, and it has cut it down to just the first item in the feed (which was what I was after, sorry if I wasnt clear..) Now however, I seem to have lost the items from the feed, particularly the title which I write twice, once as a title and the other with md5 to create an item_id. Here is the full code and I have printed out the results of the echos and the query itself below: libxml_use_internal_errors(true); //$RSS_DOC = simpleXML_load_file($feed_url); $RSS_DOC = simpleXML_load_file('http://rss.cnn.com/rss/edition.rss'); if (!$RSS_DOC) { echo "Failed loading XML\n"; foreach(libxml_get_errors() as $error) { echo "\t", $error->message; } } $rss_title = $RSS_DOC->channel->title; $rss_link = $RSS_DOC->channel->link; $rss_editor = $RSS_DOC->channel->managingEditor; $rss_copyright = $RSS_DOC->channel->copyright; $rss_date = $RSS_DOC->channel->pubDate; $feed_url = 'http://rss.cnn.com/rss/edition.rss'; //Loop through each item in the RSS document //foreach($RSS_DOC->channel->item as $RSSitem) //{ $item_id = md5($RSSitem->title[0]); $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[0]; $item_date = date("Y-m-j G:i:s", strtotime($RSSitem->pubDate)); $item_url = $RSSitem->link; echo "Processing item '" , $item_id , "' on " , $fetch_date , "<br/>"; echo $item_title, " - "; echo $item_date, "<br/>"; echo $item_url, "<br/>"; // Does record already exist? Only insert if new item... $item_exists_sql = "SELECT item_id FROM rssingest where item_id = '" . $item_id . "'"; $item_exists = mysql_query($item_exists_sql); if(mysql_num_rows($item_exists)<1) { echo "<p>Inserting new item..</p>"; $item_insert_sql = "INSERT INTO rssingest(item_id, feed_url, item_title, item_date, item_url, fetch_date) VALUES ('" . $item_id . "', '" . $feed_url . "', '" . $item_title . "', '" . $item_date . "', '" . $item_url . "', '" . $fetch_date . "')"; $insert_item = mysql_query($item_insert_sql); echo "Query: $item_insert_sql"; } else { echo "<font color=blue>Not inserting existing item..</font><br/>"; } echo "<br/>"; The printed screen looks like this:
  19. Hi all, I am retrieving an RSS feed and if it isnt already in the database, write to it. The problem is that this grabbing all of the feeds, when I only want to check and or write the first one. This is the original code with the foreach in, I have tried the following: $limit = 1; for($x=0;$x<$limit;$x++) { but am having no joy, I thinmk I am close, but not enough! Here is the main code (database connection made already and the sql is reading and writing fine): <?php libxml_use_internal_errors(true); //$RSS_DOC = simpleXML_load_file($feed_url); $RSS_DOC = simpleXML_load_file('FEED IN HERE/'); if (!$RSS_DOC) { echo "Failed loading XML\n"; foreach(libxml_get_errors() as $error) { echo "\t", $error->message; } } foreach($RSS_DOC->channel->item as $RSSitem) { $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_date = date("Y-m-j G:i:s", strtotime($RSSitem->pubDate)); $item_url = $RSSitem->link; echo "Processing item '" , $item_id , "' on " , $fetch_date , "<br/>"; echo $item_title, " - "; echo $item_date, "<br/>"; echo $item_url, "<br/>"; // Does record already exist? Only insert if new item... $item_exists_sql = "SELECT item_id FROM rssingest where item_id = '" . $item_id . "'"; $item_exists = mysql_query($item_exists_sql); if(mysql_num_rows($item_exists)<1) { echo "<p>Inserting new item..</p>"; $item_insert_sql = "INSERT INTO rssingest(item_id, feed_url, item_title, item_date, item_url, fetch_date) VALUES ('" . $item_id . "', '" . $feed_url . "', '" . $item_title . "', '" . $item_date . "', '" . $item_url . "', '" . $fetch_date . "')"; $insert_item = mysql_query($item_insert_sql); echo "Query: $item_insert_sql"; } else { echo "<font color=blue>Not inserting existing item..</font><br/>"; } echo "<br/>"; } } Thanks, G
  20. All, In my registration script I am trying to check if an email address already exists (yawn I know), and I am stuck. The code highlighted in bold is where I want to check if the email exists (notice that form checking is done above that, including sorting out the email address that the user enters) and if it doesnt insert data into the table. Trouble is that on loading the page it simply states the 'already submitted' error before an email is even entered into the form: if(isset($_POST['name']) && !empty($_POST['name']) AND isset($_POST['email']) && !empty($_POST['email']) AND ($_POST['password']) && !empty($_POST['password'])){ $name = mysql_escape_string($_POST['name']); // Turn our post into a local variable $email = mysql_escape_string($_POST['email']); $password = mysql_escape_string($_POST['email']);// Turn our post into a local variable } $name = mysql_escape_string($_POST['name']); $email = mysql_escape_string($_POST['email']); $password = mysql_escape_string($_POST['password']); if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){ // Return Error - Invalid Email $msg = 'The email you have entered is invalid, please try again.'; }else{ // Return Success - Valid Email $msg = 'Your account has been made, <br /> please verify it by clicking the activation link that has been sent to your email.'; } $hash = md5( rand(0,1000) ); // Generate random 32 character hash and assign it to a local variable. // Example output: f4552671f8909587cf485ea990207f3b [b]$emailCheck = mysql_query("SELECT email FROM users WHERE email = '".$email."'"); if (mysql_num_rows($emailCheck) > 0) { echo "already submitted"; } else {[/b] // We have a match, activate the account mysql_query("INSERT INTO users (username, password, email, hash) VALUES( '". mysql_escape_string($name) ."', '". mysql_escape_string(md5($password)) ."', '". mysql_escape_string($email) ."', '". mysql_escape_string($hash) ."') ") or die(mysql_error()); Thanks in advance, G
  21. Hi, The following code is giving me a series of errors and headaches, the errors of which are posted after. It is a script that takes an image and turns it into a thumbnail. the image in question is stored in a file system while the value is called from a database ($image1 would be hello.jpg): $pathToImages = "files/"; $pathToThumbs = "thumbs/"; // open the directory $dir = opendir( $pathToImages ); // parse path for the extension $info = pathinfo($pathToImages.$image1); // continue only if this is a JPEG image if (( strtolower($info['extension']) == 'jpg' )|| ( strtolower($info['extension']) == 'gif' )) { getimagesize($pathToImages.$image1); $height = $image1[1]; $width = $image1[0]; $scale = min(100/$width, 100/$height); # If the image is larger than the max shrink it if ($scale < 1) { $width = floor($scale*$width); $height = floor($scale*$height); } // create a new temporary image $tmp_img = imagecreatetruecolor( $width, $height ); // copy and resize old image into new image imagecopyresized( $tmp_img, 0, 0, 0, 0, $width, $height ); // save thumbnail into a file imagejpeg( $tmp_img, "{$pathToThumbs}{$image1}" ); } The errors I get are: "Division by zero" on this line: $scale = min(100/$width, 100/$height); "Wrong parameter count for imagecopyresized() " from this line: imagecopyresized( $tmp_img, 0, 0, 0, 0, $width, $height ); and finally: "imagejpeg(): supplied argument is not a valid Image resource" from this line: imagejpeg( $tmp_img, "{$pathToThumbs}{$image1}" ); Looking at my code and echoing bits out I believe my issue is due to gettting details from the variable: $image1, but I might be wrong. Anyone have any ideas? Thanks, G
  22. Hi, I am trying to resize an image on upload the problem is that I think I am over complicating it by running a seperate function for each file type, added to the fact that I get an error which I will explain after the following code: if (($HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/png")) { if (($HTTP_POST_FILES['userfile']['type'])=="image/gif"){ function resizeImage($HTTP_POST_FILES['userfile']['type'])) { $imgSize = getimagesize($HTTP_POST_FILES['userfile']['type']); $imgWidth = $imgSize[0]; $imgHeight = $imgSize[1]; $newWidth = "60"; $newHeight = "60"; $source = imagecreatefromjpeg($HTTP_POST_FILES['userfile']['type']); $thumb1 = imagecreatetruecolor($newWidth, $newHeight); imagecopyresized($thumb1, $source, 0, 0, 0, 0, $newWidth, $newHeight, $imgWidth, $imgHeight); header('Content-type: image/jpeg'); // <-- you need that! imagejpeg($thumb1); } } //After this point rename file and insert value to database. As you can see I will need to run this function for every file type, gif, jpeg etc and I get an error: on the following line: function resizeImage($HTTP_POST_FILES['userfile']['type'])) : Parse error: parse error, unexpected '[', expecting ')' Thanks, G
  23. Ok, Here is the setting up of POST: $_POST['username'] = $row ["username"]; $_POST['supplierid'] = $id; if (!isset($_POST['service1selected'])) { $service1selected = 'null'; }else{ $service1selected = $_POST['service1selected']; } $service1count = isset($_POST['service1count']) ? $_POST['service1count'] : ""; By all accounts I seem to have the checkbox and drop down output in the browser ok, the checkboxes look like when you check them and hit submit they are set to be inserted into the database, but it is not working which makes me suspect I have missed something, perhaps even in the form part...
  24. Hi all, I have script with conditions in, on these conditions being met certain html is printed in my php. The problem I am haviing is getting the values from the html into my post array. The post array is working fine as I have tested it: <?php if($service1 == "true"){ echo "<p>The price for service1 is: £$service1price, type of rate: $service1type. Tick this box if you want to enquire on this service:<input type=\"checkbox\" name=\"service1selected\" value=\"true\"></p>"; echo "<p>Please select the number of people requiring this service:"; $display ='<select size="1" name="service1count">'; foreach(array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10+') as $value) { $selected = (isset($_POST['service1count']) && $_POST['service1count'] == $value ? ' selected="selected"' : ''); $display .= "<option value='$value'$selected>$value</option>\n"; } $display .= '</select></p>'; echo $display; } ?> As another note, when you tick a box or select something from a drop down and hit submit the page returns without the values you just entered, the checkboxes are empty etc. Here is the html for the form element if that helps... <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title><?php print $page ?> </title> </head> <form name="form1" method="post" action="supplierenquiryform.php?id=<?php echo($_GET['id']); ?>"> <tr><td><input type="hidden" name="id" value="<?php echo($_GET['id']); ?>"> <p><input name="submit" type="submit" value="submit"></p> </form> </html> 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.