Jump to content

jason360

Members
  • Posts

    77
  • Joined

  • Last visited

Everything posted by jason360

  1. Okay...thanks for the info. Looks like I got a big job ahead of me switching to mysqli.
  2. Hello, I am trying to insert this string into my data base but it is failing and I am getting my die message. Anyone see why this is not working? I am connected to my database too. $string="Toyota, Volkswagen, Samsung, Ford, HewlettPackard"; $string=explode(',',$string); foreach($string as $val) { $val=strtolower($val); mysql_query('INSERT INTO companies (brands) VALUES ("'.$val[0].'")') or die ('fail insert'); }
  3. Hey guys, I am stumped on this htaccess write rule. I currently have this rule functioning: RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /item\.php\?pid=([a-z0-9]+)\ HTTP/ [NC] RewriteRule ^item\.php$ http://www.mysite.com/%1? [R=301,L] RewriteRule ^([-a-z0-9]+)$ /item.php?pid=$1 [NC,L] Original url: http://www.mysite.com/item.php?pid=2015-hyundai-genesis-coupe enabling this url: http://www.mysite.com/2015-hyundai-genesis-coupe What I require is a url like this: http://www.mysite.com/item/2015-hyundai-genesis-coupe I tried a bunch of things with no success. Anyone familiar with this? Thanks!
  4. Hey guys, I am not sure how to phrase this WHERE statement. I currently have this: WHERE approved = "1" AND item_gender="1" OR item_gender="3" It seems to be omitting the 'approved' part. What I require is that approved=1 must be adhered to regardless, but item_gender can be equal to 1 or 3. Any ideas what I am doing wrong? Thanks!
  5. Thanks for the prompt reply Psycho. I used your wildcard clean up and also found my problem. When being posted I was getting \" instead of just \. Used stripslashes function. Working like a charm now. I couldn't figure it out...I felt like i was on crazy pills...haha Thanks again! JK
  6. UPDATE: I realize it was this term triggering my preg_match: 42" AJ Slick How can I get it to accept " ' and + This is what I am using now: if(preg_match('/[^a-z0-9\-\_\,\!\?\+\"\'\ \.]+/i',$_POST['title'])) { $err[]='<p class="error" style="color: #ed1c24;">Your Name contains invalid characters!</p>'; }
  7. Anyone know why my preg_match is being triggered by this term: 3D Hobby Shop To me it should allow letters and numbers etc. My php: if(preg_match('/[^a-z0-9\-\_\,\!\?\+\ \.]+/i',$_POST['title'])) { $err[]='<p class="error" style="color: #ed1c24;">Your Title contains invalid characters!</p>'; }
  8. Hey guys, I am not sure how to do a proper range in my if statement. I need a range where count is between 1 and 10. I am using this statement below, but it is just considering the $count<=10 and 0 is included in this statement. I require a different function for $count = 0. Thanks in advance! if ($count <= 10 && $count >= 1)
  9. Thanks QuickOldCar...that was simple.
  10. Hey guys, I am stuck on this piece of code. Within the function I am using I need to include an mysql query. I am not sure how to insert it within the echo. Currently the query works but the code stops once close the '' and </ul> and </section> are cut out. Please note that there is alot more code within the echo, not just the section and ul. Just simplified it for my question. Any help would be appreciated. Thanks <?php $query = mysql_query('SELECT id FROM videos WHERE user="'.$id.'"'); list ($video_id) = mysql_fetch_array($query); if ($video_id != '') { echo '<section> <ul >'; $query = mysql_query('SELECT video FROM videos WHERE id="'.$id.'" ORDER BY RAND()'); $i = 0; class myCounter implements Countable { public function count() { static $count = 0; return ++$count; } } $counter = new myCounter; while ($row = mysql_fetch_array($query)) { if($i % 5 === 0) { } echo "<li data-path='feeds/api/videos/".$row['video']."' ></li>"; $i++; } '</ul> </section>'; ?>
  11. Thanks @mac_gyver I was able to make a large pool of results using the UNION function in my query. Here is a link if anyone else comes across this situation in the future: http://www.w3schools.com/sql/sql_union.asp
  12. I have started a function with various if statements and a counter. The individual queries are quite complicated. I have been using individual queries with a counter and if statements, however when a category has 4 or more results it just takes over the whole function and the other categories are not included. I figured explaining it this way would be simpler.
  13. Hey guys I am stuck on how to best create a php function to do the following. I need to echo out 4 restaurants. I have a database of numerous restaurant categories: breakfast, lunch, dinner, and coffee. In this database some categories have more results than others. Basically I want to randomly choose results from each category query, Breakfast, Lunch, and dinner to create 4 echoed results. (I understand that one category will have an extra result as there are 3 categories and 4 echoed results.) I do not want one category of restaurant to bump out another category because it has more results. Also, if there are not enough or no results from one category, I want extra results from the other queries to make up for it so that there are always 4 echoed items. Finally, if there are not enough results from breakfast, lunch, dinner to make 4 echoed items, I would like Coffee to fill the 4 required results. Randomly echo 4 results from the below primary queries: Primary Query: Breakfast Restraunts Query Primary Query: Lunch Restraunts Query Primary Query: Dinner Restraunts Query Get results from secondary query if Primary queries can’t echo 4 results: Secondary Query: Coffee Shops Query I hope this makes sense. I understand how to do the mysql queries, I just don't know how to do the php function to echo the results as required. Any help would be appreciated!
  14. Thanks Ch0cu3r! That was simple. I didn't know you could use > and < in the query.
  15. Hello, I am working on this function that echo's out images from my database restricted to 10 images with 4 default images if the database is empty. <?php $query = mysql_query('SELECT image_id, image_expiry FROM images ORDER BY RAND() LIMIT 10'); $i = 0; class myCounter3 implements Countable { public function count() { static $count = 0; return ++$count; } } $counter = new myCounter3; while ($row = mysql_fetch_array($query)) { if($i % 10 === 0) { } echo '<img src="http://www.mysite.com/'.$row['image_id'].'.jpg" width="300" height="auto"/>'; $i++; } for (; $i <= 4; $i++) { echo '<img src="http://www.mysite.com/default.jpg" width="300" height="auto"/>' } ?> I need to include an image expiry function with the function above, but I am not sure how to properly include it. Here is my planned expiry function (each image as an expiry date). $today = date("Y-m-d", time()); $expiry = $row['image_expiry'] if( $today > $expiry) { ## ignore expired image } else { ## display image } Bottom line I need to exclude expired images from being echoed out in the first function. Thanks in advance. Everything I have tried hasn't worked.
  16. Hey Guys, Just an update. I was able to figure the problem out by adding stripslashes() to the POST. if(preg_match("/[^a-zA-Z0-9\-\_\,\!\?\.\'\"\ \/]+/i",stripslashes($_POST['article_title'])))
  17. Thanks requinix! Worked like a charm.
  18. Hey guys, I am using a function that echos out 10 images from my database. I need to have a minimum of 4 echoed images. Some categories have less than 4 images, so I would like to have a default image(s) echoed out if the database has 4 or less images. Does anyone know how I can do this? Below is the code I am using now to echo out the 10 images. Thanks in advance: <?php $query = mysql_query('SELECT image_id FROM images ORDER BY RAND() LIMIT 10'); $i = 0; class myCounter3 implements Countable { public function count() { static $count = 0; return ++$count; } } $counter = new myCounter3; while ($row = mysql_fetch_array($query)) { if($i % 10 === 0) { } echo '<img src="http://www.mysite.com/'.$row['image_id'].'.jpg" width="300" height="auto"/>'; $i++; } ?> Default Image: <img src="http://www.mysite.com/default.jpg" width="300" height="auto"/>
  19. Hi PHP Bad Boy, I tried the snippet and it echoed 0. Do you think that maybe remove slashes should be used on the $_POST['article_title']?
  20. Hey guys, I am stuck on this preg_match if statement. I want to allow ' and " in the variable string but for some reason it keeps reporting invalid characters when I add ' or " to the string. Any help would be appreciated as I have tried tons of combinations after searching google. Thanks! if(preg_match("/[^a-zA-Z0-9\-\_\,\!\?\.\'\"\ \/]+/i",$_POST['article_title'])) { $err[]='<p class="error" style="color: #ed1c24;">Your Title contains invalid characters!</p>'; }
  21. am coming across the problem. When I use copied text in my input form it gives some characters this � character. I am not sure how to post text so this doesn't happen. Example: This line copied: The 976cc, 101-hp Rotax® 1000R V-Twin engine is known for its reliable power. Produces: The 976cc, 101-hp Rotax� 1000R V-Twin engine is Can-Am's most powerful side-by-side engine. My code: if (get_magic_quotes_gpc()) { $description_clean_magic = stripslashes($description); } else { $description_clean_magic = $description; }
  22. Problem solved: $result = mysql_query('SELECT COUNT(*) FROM comment_votes WHERE vote_com_writer_id = "'.$d['user_id'].'" AND vote_com_rank = "1"'); $positive_votes = mysql_result($result, 0); $result2 = mysql_query('SELECT COUNT(*) FROM comment_votes WHERE vote_com_writer_id = "'.$d['user_id'].'" AND vote_com_rank = "2"'); $negative_votes = mysql_result($result2, 0); $vote = $positive_votes - $negative_votes;
  23. Hey guys, I am trying to make two queries providing $result and $result2. I would like to subtract the two results to create a total for the vote (negative vote being possible). Therefore on an empty query the result value would have to be zero. My subtraction function isn't working. Does anyone know what I am doing wrong? I am getting no result. Thanks in advance! My code: $result = mysql_query('SELECT COUNT(*) FROM comment_votes WHERE vote_com_writer_id = "'.$d['user_id'].'" AND vote_com_rank = "1"'); $positive_votes = mysql_result($result, 0); $result2 = mysql_query('SELECT COUNT(*) FROM comment_votes WHERE vote_com_writer_id = "'.$d['user_id'].'" AND vote_com_rank = "2"'); $negative_votes = mysql_result($result2, 0); list($vote) = $positive_votes - $negative_votes;
  24. Awesome thanks Boompa! It sure didn't seem right what I had.
×
×
  • 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.