User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 375,198 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,986 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 1495 | Replies: 38 | Solved
Reply
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,057
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 229
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: display image from databse

  #21  
Apr 2nd, 2008
should the where clause look something like this

Help with Code Tags
(Toggle Plain Text)

$sql="UPDATE images_broad SET broad1='$broad1name2' WHERE broad1=`1`";

$sql="UPDATE images_broad SET broad1='$broad1name2' WHERE broad1=`1`";

if this line is correct it is effecting the preview page. when that page is accessed is says there is a problem with the mysql line

No. You are trying to update broad1 column where broad1 = 1. I hope your table has an id(counter) field which is an auto-increment field ? Use that to update the record.
if this line is correct it is effecting the preview page. when that page is accessed is says there is a problem with the mysql line

Help with Code Tags
(Toggle Plain Text)

while($row=mysql_fetch_array($result, MYSQL_ASSOC)){

while($row=mysql_fetch_array($result, MYSQL_ASSOC)){

should the while be taken out and the line edited so it looks like this

Help with Code Tags
(Toggle Plain Text)

$result=mysql_fetch_array($result, MYSQL_ASSOC)){

Basically, If your table has only 1 record, you don't need a while loop. But if your table has more than 1 record, then to fetch all the records, you have to use a while loop. My suggestion for you is, search for "file upload+php" in google. You will get alot of examples. Use one to upload an image to the server. While you upload an image to the server, save the path in the table(Insert a record and not update). So, whenever you upload an image, a path will be in the table. And for listing the images in the preview screen, get all the records, use a while loop to fetch all the records and then display it using <img src> tag.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Feb 2008
Posts: 271
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: display image from databse

  #22  
Apr 2nd, 2008
on the preview page the code used to display the image which is

	$query = "SELECT * FROM images_broad";
	$result=mysql_query($query);

	while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
	echo '<img src="'.$row['broad1'].'"/>';
	}

i have changed the code so it prints out what is in the table the code now looks lie this

$query = "SELECT broad1 FROM images_broad";
$result=mysql_query($query);
print_r(mysql_fetch_array($result));

the result that it prints on the screen seems to suggest that the same image is being entered into the table twice. here is what was printed

Array ( [0] => image/thumbs/thumb_1207138801.gif
[broad1] => image/thumbs/thumb_1207138801.gif )
Reply With Quote  
Join Date: Feb 2008
Posts: 271
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: display image from databse

  #23  
Apr 2nd, 2008
i have set an id counter but when i try to set the where clause to id=1 it does not like the while loop on the preview page. the path is being stored to the database fine but i think it is storing it more than once.

i need to look up the code so when the image is being displayed it only displays one row from the table and not all the rows thus taking out the while loop.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,057
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 229
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: display image from databse

  #24  
Apr 2nd, 2008
Array ( [0] => image/thumbs/thumb_1207138801.gif
[broad1] => image/thumbs/thumb_1207138801.gif )

Thats because, mysql_fetch_array returns both numeric index array and associated array name. Try mysql_fetch_array($result,MYSQL_ASSOC) and print !
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,057
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 229
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: display image from databse

  #25  
Apr 2nd, 2008
And, if your table has more than 1 row, use while loop.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Feb 2008
Posts: 271
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: display image from databse

  #26  
Apr 2nd, 2008
i have changed the code now so it is only trying to display one row from the table but i am getting an error which is as follows but do you no what this means.


Wrong parameter count for mysql_fetch_row() in /home/acmeart/public_html/mercury/broad_prev.php on line 58

the code which i am using now looks like this

$query = "SELECT * FROM images_broad WHERE id=`1`";
$result=mysql_query($query);
while($row=mysql_fetch_row($result, MYSQL_ASSOC)){
echo '<img src="'.$row['broad1'].'"/>';
}
Reply With Quote  
Join Date: Feb 2008
Posts: 271
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: display image from databse

  #27  
Apr 2nd, 2008
line 58 is the while loop line
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,057
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 229
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: display image from databse

  #28  
Apr 2nd, 2008
$query = "SELECT * FROM images_broad WHERE id=`1`";
$result=mysql_query($query);
while($row=mysql_fetch_row($result, MYSQL_ASSOC)){
echo '<img src="'.$row['broad1'].'"/>';
}
Should be
  1. $query = "SELECT * FROM images_broad WHERE id=`1`";
  2. $result=mysql_query($query);
  3. while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
  4. echo '<img src="'.$row['broad1'].'"/>';
  5. }
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Feb 2008
Posts: 271
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: display image from databse

  #29  
Apr 2nd, 2008
that code now gives me the error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

it does not like the while loop for some reason.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,057
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 229
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: display image from databse

  #30  
Apr 2nd, 2008
Huh! Well, it likes while loop if the resource id provided to it is correct. Check your query again. Maybe some details are missing.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb MySQL Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 2:25 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC