Jump to content

derek barnstorm

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

derek barnstorm's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Very sorry about posting in the wrong place. I clicked on the wrong board by mistake. Oops!
  2. Hi, I have been trying to paginate the following script: <?php if($_SERVER[php_SELF]=="/include/headlist.inc.php") { header("Location: /index.php"); exit; } include("include/get_profile_fields.inc.php"); $connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select database."); $sql = "SELECT * FROM $tbl_profiles WHERE profile_id != \"00000001\""; $result = @mysql_query($sql,$connection) or die("Couldn't execute profile query."); $num=mysql_num_rows($result); if($num < 1){ echo "<p align=\"center\">No Members found.</p>"; ?> <? include("include/footer.inc.php"); exit; } ?> <table border="1" align="center" cellpadding="4" cellspacing="0" width="100%"> <? if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 2; while($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; $p_name = $row['p_name']; $profile_url = $row['profile_url']; $location = $row['location']; $profile_id = $row['profile_id']; $sql_img = "SELECT * FROM $tbl_images WHERE image_id = \"$profile_id\" AND default_pic = \"yes\""; $result_i = @mysql_query($sql_img,$connection) or die("Couldn't execute image query."); $irow = mysql_fetch_array($result_i); $friend_pic = $irow['image']; $friend_url = $irow['url']; if(empty($friend_url)) {$newfurl="$imgdir";}else{$newfurl="$userdir/$friend_url";} if(empty($friend_pic))$friend_pic="pic.gif"; $friend_img="/$newfurl/$friend_pic"; echo " <td> <p><a href=\"$userurl/$profile_url\"><IMG SRC=\"../../thumbs/phpThumb.php?src=$friend_img&w=100\" align=\"absmiddle\" border=\"0\"><b> $p_name</a></b></p> <p>Location: $location</p> </td> "; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } include("include/footer.inc.php"); exit; ?> I found the this tutorial http://www.tonymarston.net/php-mysql/pagination.html amongst others but after hours of messing about I'm still having problems. Using that tutorial I adapted the above script to the one below, but it won't connect to the database. Every other way I've tried it, just gives errors. <?php if($_SERVER[php_SELF]=="/include/headlist.inc.php") { header("Location: /index.php"); exit; } include("include/get_profile_fields.inc.php"); if (isset($_GET['pageno'])) { $pageno = $_GET['pageno']; } else { $pageno = 1; } // if $connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select database."); $query = "SELECT COUNT(*) FROM $tbl_profiles WHERE profile_id != \"00000001\""; $result = @mysql_query($query,$connection) or die("Couldn't execute profile query."); $query_data = mysql_fetch_row($result); $numrows = $query_data[0]; $rows_per_page = 15; $lastpage = ceil($numrows/$rows_per_page); $pageno = (int)$pageno; if ($pageno > $lastpage) { $pageno = $lastpage; } // if if ($pageno < 1) { $pageno = 1; } // if $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; $query = "SELECT * FROM table $limit"; $result = @mysql_query($query,$connection) or die("Couldn't execute profile query."); $num=mysql_num_rows($result); if($num < 1){ echo "<p align=\"center\">No Members found.</p>"; ?> <? include("include/footer.inc.php"); exit; } if ($pageno == 1) { echo " FIRST PREV "; } else { echo "<a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> "; $prevpage = $pageno-1; echo "<a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> "; } // if echo " ( Page $pageno of $lastpage ) "; if ($pageno == $lastpage) { echo " NEXT LAST "; } else { $nextpage = $pageno+1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> "; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> "; } // if ?> <table border="1" align="center" cellpadding="4" cellspacing="0" width="100%"> <? if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 2; while($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; $p_name = $row['p_name']; $profile_url = $row['profile_url']; $location = $row['location']; $profile_id = $row['profile_id']; $sql_img = "SELECT * FROM $tbl_images WHERE image_id = \"$profile_id\" AND default_pic = \"yes\""; $result_i = @mysql_query($sql_img,$connection) or die("Couldn't execute image query."); $irow = mysql_fetch_array($result_i); $friend_pic = $irow['image']; $friend_url = $irow['url']; if(empty($friend_url)) {$newfurl="$imgdir";}else{$newfurl="$userdir/$friend_url";} if(empty($friend_pic))$friend_pic="pic.gif"; $friend_img="/$newfurl/$friend_pic"; echo " <td> <p><a href=\"$userurl/$profile_url\"><IMG SRC=\"../../thumbs/phpThumb.php?src=$friend_img&w=100\" align=\"absmiddle\" border=\"0\"><b> $p_name</a></b></p> <p>Location: $location</p> </td> "; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } include("include/footer.inc.php"); exit; ?> Any help or a point in the right direction would be great. Cheers.
  3. Okay, thanks for your replies, I think I'll try to go about it a different way. Cheers, Des.
  4. Hi, another question. I am using the following script to upload images to a database. I am pretty new to PHP, but what I would like to do is, modify the script so that it handles MP3 uploads instead of image uploads. Is that possible with this script? If so, has anyone got any ideas how I would go about it? Thanks, Des. Script: <?php if($_SERVER[php_SELF]=="/include/profiles/upload.inc.php") { header("Location: /index.php"); exit; } $image_id = $_POST['image_id']; $userfile = $_POST['userfile']; //UPLOAD CHECK $connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect to database."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select database."); $sql = "SELECT * FROM $tbl_images WHERE image_id = \"$auth[member_id]\" "; $result = @mysql_query($sql,$connection) or die("Couldn't execute image check query."); $num=mysql_num_rows($result); if($num == "0") { $make_default = "yes"; } else { $make_default = "no"; } if($num > "5") { ?> <p><b>You may have 1 picture. Please delete your old picture before uploading a new one:</b></p> <table cellpadding="4" cellspacing="0" width="100%"> <? while ($row = mysql_fetch_array($result)) { $location ="$row[directory]/$row[image]"; $showimg="/$userdir/$row[url]/$row[image]"; echo "<tr> <td> <p> <form action=\"remove_pic.php\" method=\"POST\"> <p><input type=\"checkbox\" name=\"remove\" checked> <IMG SRC=\"../../thumbs/phpThumb.php?src=$showimg&w=150\" border=\"0\"> <br><input type=\"submit\" name=\"submit\" value=\"Delete!\"> <input type=\"hidden\" name=\"filename\" value=\"$location\"> <input type=\"hidden\" name=\"file\" value=\"$row[image]\"></p> </form> </td> </tr>"; } ?> </table> <p><input type=button value="Cancel" onClick="history.go(-1)"></p> <? exit; } else { //END Upload check //$acceptable_file_types used by upload() method // // Limit acceptable uploads based on MIME type. Common MIME types // include: text/plain, image/gif, image/jpeg image/png // To accept ONLY gifs's use the following //acceptable_file_types = "image/gifs"; // Accept GIF and JPEG files //$acceptable_file_types = "image/gif|image/jpeg|image/pjpeg"; // Accept all image files $acceptable_file_types = "image"; // Accept ALL files (NOT recommended!) $acceptable_file_types = ""; $connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect to database."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select database."); $sql = " SELECT profile_id, directory, profile_url FROM $tbl_profiles WHERE profile_id = \"$auth[member_id]\" "; $result = @mysql_query($sql,$connection) or die("Couldn't execute profile query."); $num=mysql_num_rows($result); while ($row = mysql_fetch_array($result)) { $directory = $row['directory']; $profile_url = $row['profile_url']; $image_id = $row['profile_id']; } $url = "$usrdir$profile_url/"; require("fileupload.class.php"); // Path to the directory where uploaded files will be saved. MUST end // with a trailing slash unless you use $path = ""; $path = "$directory/"; // If no extension is supplied, and the browser or PHP can not figure // out what type of file it is, you can add a default extension $default_extension = ".jpg"; // example: ".jpg" // Handles identically named uploaded files. // // OPTIONS: // 1 = overwrite mode // 2 = create new with incremental extention // 3 = do nothing if exists, highest protection $mode = 1; /* ** ** UPLOAD LOGIC ** -------------------------------------------------------------------- ** */ if (isset($_REQUEST['submitted'])) { /* A simpler way of handling the submitted upload form might look like this: $my_uploader = new uploader('en'); // errors in English $my_uploader->max_filesize(30000); $my_uploader->max_image_size(800, 800); $my_uploader->upload('userfile', 'image/gif', '.gif'); $my_uploader->save_file('uploads/', 2); if ($my_uploader->error) { print($my_uploader->error . "<br><br>\n"); } else { print("Thanks for uploading " . $my_uploader->file['name'] . "<br><br>\n"); } */ // Create a new instance of the class $my_uploader = new uploader($_POST['language']); // for error messages in french, try: uploader('fr'); // OPTIONAL: set the max filesize of uploadable files in bytes $my_uploader->max_filesize(400000); // OPTIONAL: if you're uploading images, you can set the max pixel dimensions $my_uploader->max_image_size(600, 600); // max_image_size($width, $height) // UPLOAD the file if ($my_uploader->upload("userfile", $acceptable_file_types, $default_extension)) { $my_uploader->save_file($path, $mode); } if ($my_uploader->error) { echo $my_uploader->error . "<br><br>\n"; } else { // Print all the array details... //print_r($my_uploader->file); // ...or print the file if(stristr($my_uploader->file['type'], "image")) { echo "<img src=\"" . $url . $my_uploader->file['name'] . "\" border=\"0\" alt=\"\">"; ?><br><br> <? echo "<p align=\"center\">Return to <a href=\"$url\">my profile</a>.</p>"; $newimage = $my_uploader->file['name']; $mydir = "$directory"; $connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select database."); $sql = "SELECT * FROM $tbl_images WHERE image_id = \"$auth[member_id]\" AND default_pic = \"yes\" "; $result = @mysql_query($sql,$connection) or die("Couldn't execute image default query."); $num=mysql_num_rows($result); if($num == "0") { $make_default = "yes"; } $sql = "INSERT INTO $tbl_images (image_id, directory, image, url, displayname, default_pic) VALUES (\"$auth[member_id]\",\"$mydir\", \"$newimage\", \"$profile_url\", \"$auth[displayname]\", \"$make_default\")"; $result = @mysql_query($sql,$connection) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error()); exit; } else { $fp = fopen($path . $my_uploader->file['name'], "r"); while(!feof($fp)) { $line = fgets($fp, 255); echo $line; } if ($fp) { fclose($fp); } } } } } ?> <form enctype="multipart/form-data" action="<?= $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="hidden" name="submitted" value="true"> <input type="hidden" name="image_id" value="<?echo $image_id ?>"> <input name="userfile" type="file"> <br><br> <input type="submit" value="Upload File"> </form> <input type=button value="Cancel" onClick="history.go(-1)">
  5. Okay, thanks very much! That works a treat. I gues I should have had a good browse of the forum first. Thanks again, Des.
  6. Hi, I am using the following script to display images on a page from a database: <script type="text/javascript"> function openpopup(popurl){ var winpops=window.open(popurl,"","width=610px,height=625px,resizable") } </script> </p>Click picture to enlarge.</p> <table cellpadding="4" cellspacing="0" width="100%"> <tr> <? $db = @mysql_select_db($db_name, $connection) or die("Couldn't select database."); $sql = "SELECT * FROM $tbl_images WHERE directory = \"$directory\""; $result = @mysql_query($sql,$connection) or die("Couldn't execute query."); while ($row = mysql_fetch_array($result)) { if($row[default_pic] == "yes") { $default_border = "1"; } else { $default_border = "0"; } $showimg="/$userdir/$row[url]/$row[image]"; $location ="$row[directory]/$row[image]"; if($profile_id == $auth[member_id]) { $del_pic = "<form action=\"../../include/profiles/delete_pic.php\" method=\"POST\"><input type=\"hidden\" name=\"file\" value=\"$row[image]\"><input type=\"hidden\" name=\"filename\" value=\"$location\"><input type=\"hidden\" name=\"image_id\" value=\"$profile_id\"><input type=\"submit\" value=\"Delete\"></form>"; } else { $del_pic = ""; } if($profile_id == $auth[member_id]) { $default_pic = "<form action=\"../../include/profiles/make_default.php\" method=\"POST\"><input type=\"hidden\" name=\"file\" value=\"$row[image]\"><input type=\"hidden\" name=\"profile_id\" value=\"$profile_id\"><input type=\"submit\" value=\"Default\"></form>"; } else { $default_pic = ""; } echo "<td align=\"center\" valign=\"top\"><p><a href=\"javascript:openpopup('showpic.php?img=$row[image]')\"><IMG SRC=\"../../thumbs/phpThumb.php?src=$showimg&w=200\" border=\"$default_border\"></a></p><p>$del_pic $default_pic</p></td></tr><tr>"; } ?> </tr> </table> <p align="center">Back to <a href="<?echo $PHP_SELF ?>">my profile.</a></p> But, when the iages are displayed, they appear in a list. What I want is to have them appear in 3 colums at a time... i.e. <td>myimage.jpg</td><td>myimage.jpg</td><td>myimage.jpg</td> </tr> <tr> <td>myimage.jpg</td><td>myimage.jpg</td><td>myimage.jpg</td> </tr> How would I go about doing this? Thanks, Des
×
×
  • 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.