|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
One For Each
i have included a rating script in a gallery script using include(). the drop down rating box appears only once when i test the script, but i need it to appear beside each image. how do i do this?
<?php // Connects to sql server and logs in with username and password // if successful, then the script moves on to displaying the gallery. $connect=mysql_connect("localhost","xxxx","xxx") or die("couldnt connect to sql server"); $db= mysql_select_db("dbname") or die ("couldnt select database"); include("./rate.php"); // Ive set the number of photos per page, in this case I only have 7 photos // so I want to display 1 photo per page. $per_page = 1; // Selects all of the data from database $sql_text = ("SELECT * from photogallery ORDER BY id DESC"); // Sets page number, if no page is specified, it will create page 1 if(!$page) { $page = 1; } $prev_page = $page - 1; $next_page = $page + 1; $query = @mysql_query($sql_text); // Sets up specified page $page_start = ($per_page * $page) - $per_page; $num_rows = @mysql_num_rows($query); if($num_rows <= $per_page) { $num_pages = 1; } else if (($num_rows % $per_page) == 0) { $num_pages = ($num_rows / $per_page); } else { $num_pages = ($num_rows / $per_page) + 1; } $num_pages = (int) $num_pages; if (($page > $num_pages) || ($page < 0)) { error("You have specified an invalid page number"); } $sql_text = $sql_text . " LIMIT $page_start, $per_page"; $query = mysql_query($sql_text); ?> <!-- This starts the web page with HTML and PHP embedded. --> <!-- It also counts how many photos are present in the photo gallery. --> <title>My Photo Gallery</title> <body bgcolor="#ffffff"> <blockquote> There are currently<font color="red"> <?php echo "$num_rows"; ?> </font> photos in My Photo Gallery<p> <!-- It loops through the rows and obtains the data that we created in the table. --> <?php while ($result = mysql_fetch_array($query)) { $title = $result["title"]; $photo = $result["photo"]; $linkToFullPhoto = $result["link2Full"]; // Using HTML "img" tags for the photos, it selects the photo by it's "id" number echo $title.'<br /> <a href="'.$linkToFullPhoto.'"> <img src="'.$photo.'" border="0"> </a><p /> <hr width="400" align="left">'; } // This displays the "Previous" link if ($prev_page) { echo "<a href=\"$PHP_SELF?page=$prev_page\">< Prev</a>"; } // This loops the Pages and displays individual links corresponding // to the photos. for ($i = 1; $i <= $num_pages; $i++) { if ($i != $page) { echo " <a href=$PHP_SELF?page=$i>$i</a>"; } else { echo " $i "; } } // This displays the "Next" link. if ($page != $num_pages) { echo " |<a href=\"$PHP_SELF?page=$next_page\"> Next ></a>" ; } ?> </blockquote> </body> </html> _____________ |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > One For Each |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|