Jump to content

Mysql and Pulling Data


Sheets

Recommended Posts

id: 20 Reason: this is a test
id: 21 Reason: Tests
id: 22 Reason: Lolcatz
id: Reason: 
id: Reason: 
id: Reason: 
id: Reason: 
id: Reason: 
id: Reason: 
id: Reason: 
id: Reason: 
id: Reason: 
id: Reason: 
id: Reason: 
id: Reason: 
id: Reason: 
id: 36 Reason: Test

 

As you can see on the 2nd code box there are id's 20,21,22 and 36 in the database the rest are not active in the database.

 

i am using using

for

to pull out the id that starts with the lowest value in the database, and only have it run until it gets to the maximum value.

	for ($id=$set_min; $set_max<=7; $id++)
{
                // $id=$set_min is pulling the smallest value and $set_max is pulling the maximum value so it stops  after it gets to 36
	$query=mysql_query("SELECT * FROM posted WHERE id = $id");
	$query_row=mysql_fetch_array($query);

	$reason = $query_row[reason];
	$pulled_id = $query_row[id];
	$pulled_pic22 = $query_row[picture];
	$href_pull = "<a href=" . "search.php?id=" . "$id" .">";

	echo "<td>" . $href_pull . "<img src=$pulled_pic22 height=200 width=150 />" . "</td>";
}

 

how would i make it so i do not pull the values 23-35 which are not in the active database.

 

Example: http://dev.hackmuch.com/of-the-day/search.php?id=36

Link to comment
Share on other sites

That is the only way i know how to. 0.o but obviously it is not working.

 

I am trying to pull the pictures out of the database, set it up so it forwards to search.php with the id that it has. however if you went to the link i posted you see there are 3 images then at the far right there is another one. It is pulling all the in between ids that are not in the database. I know there are better ways etc.. but this is all i know how at the moment.

 

function get_min() {
$min = mysql_query("SELECT MIN(id) FROM posted");
$query_min = mysql_fetch_array($min);
$min_min = $query_min[0];
return $min_min;
}
function get_max() {
$max = mysql_query("SELECT MAX(id) FROM posted");
$query_max = mysql_fetch_array($max);
$max_max = $query_max[0];
return $max_max;
}

Link to comment
Share on other sites

I think this is what you are looking for:

$sql = "SELECT id, reason, picture FROM posted WHERE id BETWEEN $set_min, AND $set_max"; //query string
$result = mysql_query($sql) or die (mysql_error()); // run a single query only once, show error on failure
while ($row=mysql_fetch_assoc($result)){ //run through the results using $row array to address returned fields by field name
//your code start
$reason = $row[reason];
$pulled_id = $row[id];
$pulled_pic22 = $row[picture];
$href_pull = "<a href=" . "search.php?id=" . "$id" .">";
echo "<td>" . $href_pull . "<img src=$pulled_pic22 height=200 width=150 />" . "</td>";
//your code end
}//job done

 

Link to comment
Share on other sites

I think this is what you are looking for:

$sql = "SELECT id, reason, picture FROM posted WHERE id BETWEEN $set_min, AND $set_max"; //query string
$result = mysql_query($sql) or die (mysql_error()); // run a single query only once, show error on failure
while ($row=mysql_fetch_assoc($result)){ //run through the results using $row array to address returned fields by field name
//your code start
$reason = $row[reason];
$pulled_id = $row[id];
$pulled_pic22 = $row[picture];
$href_pull = "<a href=" . "search.php?id=" . "$id" .">";
echo "<td>" . $href_pull . "<img src=$pulled_pic22 height=200 width=150 />" . "</td>";
//your code end
}//job done

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' AND 36' at line 1

 

Trying to fix myself ill let you know, but if you know how to fix feel free to reply :)

Link to comment
Share on other sites

$sql = "SELECT id, reason, picture FROM posted WHERE id BETWEEN $set_min AND $set_max"; //query string
$result = mysql_query($sql) or die (mysql_error()); // run a single query only once, show error on failure
while ($row=mysql_fetch_assoc($result)){ //run through the results using $row array to address returned fields by field name
//your code start
$reason = $row[reason];
$pulled_id = $row[id];
$pulled_pic22 = $row[picture];
$href_pull = "<a href=" . "search.php?id=" . "$pulled_id" .">";
echo "<td>" . $href_pull . "<img src=$pulled_pic22 height=200 width=150 />" . "</td>";
//your code end
}//job done

 

it works exactly like i want! :D thank you for your help!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.