Jump to content

sidorak95

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

Everything posted by sidorak95

  1. Thank you, however, it doesn't solve my problem. I'm looking to echo 3 rows, then some HTML code, and then resume. This won't resume fetching from the database where we left off, so I feel limit is the wrong way to go.
  2. This is what I was trying with limit: <?php mysql_connect("localhost", "", "") or die(mysql_error()); mysql_select_db("a8784hos_gpt") or die(mysql_error()); $result = mysql_query("SELECT * FROM test LIMIT 1, 3") or die(mysql_error()); $count = 0; while($row = mysql_fetch_array( $result )) { while($count < 3){ echo $row['Name'] . '<br>'; $count = $count + 1; } echo '<hr>'; } ?> However, it failed, some I'm back to square one: <?php mysql_connect("localhost", "", "") or die(mysql_error()); mysql_select_db("a8784hos_gpt") or die(mysql_error()); $result = mysql_query("SELECT * FROM test") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { echo $row['Name']; } ?>
  3. I'm sorry, I didn't see anywhere where it prohibited you from posting simple php questions. ^^ I am familiar with getting data from a database, and I was thinking of using limit, but in my tests it failed. I also fail to see the relevance of echo vs. print. While I did say I would echo something, I won't necessarily use echo and that's really not my main concern right now.
  4. Hi, I'm trying to make an art portfolio, and I'm trying to get the images from a mysql database. However, I would like the portfolio to be paged. The template I'm using by default has pages. However, it's entirely HTML. I'm looking to: -Grab x rows from database (in my case, 3) -Echo the 3 rows -Then echo the HTML code that would create a new page -Repeat until no more entries Can you do this, and if so, how? I know about pagination, but I think this approach is much simpler and I would prefer my approach. Thanks.
  5. The site is: http://www.clickcritters.com/
  6. Hi, I've been trying to find a specific text on a webpage and make a popup if it's there. A friend recommended I use cURL to try to open the page first, and then go on from there. I found a simple script on the internet: <?php function get_data($url) { $ch = curl_init(); $timeout = 5; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $data = curl_exec($ch); curl_close($ch); return $data; } $returned_content = get_data('http://www.example.com/'); echo $returned_content; ?> This works successfully on both Google and Yahoo. However, for the site in question, nothing is displayed. A quick check shows that the result is empty. I've tried setting the user-agent to Firefox, and then the webpage is now displayed. The admin of that site says that no user-agent is being blocked, except for bots in one directory that I'm not trying to access. Both file_get_contents and fopen result in an empty page. Does anyone have any idea why this is? Thanks.
  7. /facepalm I don't know how I missed that. I guess that's what I deserve for copying and pasting code snippets. Thanks!
  8. Hi, I've been trying to get a simple select statement to work in my code, and I just don't know why it returns an error. And the code is: <?php $con = mysql_connect("localhost","***","***"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("a8784hos_pets2", $con) or die ("Couldn't select database because: ".mysql_error()); $query = "SELECT * FROM species WHERE available = 1"; $petcrap = mysql_query($query) or die ("Error in number one query: $query. ".mysql_error()); $petinfo = mysql_fetch_array($petcrap); while ($row = mysql_fetch_array($petinfo)){ echo $row['petid']; } ?> I've read that this is usually because you haven't selected the database or it can't find the table, but I've run the sql query in phpmyadmin, and it comes back perfectly. I honestly have no idea what I'm doing wrong right now and would appreciate some help. Thanks.
  9. It looks like I must have accidentally put in a letter, which causes it to be blank. Now to filter out letters..... Thanks so much for your help!
  10. I did a quick google and saw a few interesting results. For your php tags are you using <? or <?= instead of <?php ?
  11. Thanks, that solved it! I should've noticed the extra one, ugh I'm slow today. And of course with every solution comes another problem. The else condition never occurs, a blank page just appears. I'm not sure why it wouldn't, its the simplest of simple codes...
  12. Wow, I can't believe I missed that. I guess I was trying to substitute while with if....... Anyways, now whatever I put in always returns a blank page with nothing in it. I experimented and put an echo in three places: <?php $con = mysql_connect("localhost","a8784hos_sid","bobafett1"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("a8784hos_adopts", $con); $adopt = $_POST['adoptid']; $uniquecode = $_POST['uniquecode']; $result = mysql_query("SELECT uniquecode, id FROM id WHERE id='$adopt'"); echo "Hi."; mysql_fetch_array($result); echo "Hi."; while ($row = mysql_fetch_array($result)){ if ($uniquecode == $row['uniquecode']){ mysql_query("DELETE FROM id WHERE id='$adopt'"); echo 'Done! <br/><br/><a href="tester.php">Go back....</a>'; } else { echo 'Bad unique code. <br/><br/><a href="tester.php">Go back....</a>'; } } echo "Hi."; ?> They all show up, so I guess it's something about the while loop....
  13. Hi, this is the first time I've asked for some help from a forum. I guess this code has sort of got me stumped. So, I have a system where a user can enter a number. The number goes into a mysql database. A random number is also generated and it is added into another column. So, I want users to be able to delete the number using the random number. I've shown it to them, and I need help working my delete script. <?php $con = mysql_connect("localhost","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("a8784hos_adopts", $con); $adopt = $_POST['adoptid']; $uniquecode = $_POST['uniquecode']; $result = mysql_query("SELECT uniquecode, id FROM id WHERE id='$adopt'"); mysql_fetch_array($result); if (($adopt == $row['id']) || ($uniquecode == $row['uniquecode'])){ mysql_query("DELETE FROM id WHERE id='$adopt'"); echo 'Done! <br/><br/><a href="tester.php">Go back....</a>'; } else { echo 'Bad unique code. <br/><br/><a href="tester.php">Go back....</a>'; } ?> So, the random number is uniquecode in the database, and the number is id. However, when I try this code, it always tell me I have a bad unique code. What am I doing wrong? Thanks.
×
×
  • 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.