Jump to content

CBStrauss

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

CBStrauss's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. well no errors is a good sign but if your field data is not display again make sure you have the names type in your php code as you do in your table field and check to make sure there is actually data in those field in your database.
  2. I guess the first question I have is the field names correct? You selecting from the same table in the second code as the first but the field names are different. In the first table your wanting data from fields called animal and country and in the second code your wanting fields firstname and surname. an easy way to use field name as variables is to add code like this in your while statement while ($row = mysql_fetch_array($result)) { extract($row); // Rest code here } now with extract($row) function you dont have to write out $row['firstname'] you can just type $firstname and it knows its the firstname field. As for the rest of your code if its the same as the first in the second except for the db I would double check your field names it seems like you might not have the names right.
  3. It doesn't matter weather you use the get or post method they both will get passed. The difference is the get method the values your passing display in the url. If you use the post method they get passed you just dont see them in the URL. Now with that being said just to cover my bases not sure if you knew that or not. Before I get into how to get the values since your calling the same page I would suggest using a conditional statement if the submit button was pressed process the code or if its loading for the first time it skips the processing code and displays your form. I usually use a switch statement Something like this <?php $req = (!isset($_REQUEST['req'])) ? 'default' : $_REQUEST['req']; switch($req){ case "submit": // Get Your Values and store it into variable $var = $_GET['city_menu']; // Then run sql to add to your database........ default: ?> // Close PHP Tags to write HTML <form target="_self" method="Get"> <select name="city_menu"> <option value="New York">New York</option> <option value="Paris">Paris</option> <option value="London">London</option> </select> [b]<input type="hidden" name="req" value="submit" /> NOTE: This was added to your code to be passed[/b] <input type="submit" name="Posted" value="Select" /> </form> <?php break; } // End Switch ?> First off I added the hidden field req in your form in bold that will decide weather to run the process code or display the form via your switch statements. Now to get the value that was selected when you hit the submit button you its accessed by the $_GET['city_menu'] if using the get method or $_POST['city_menu'] if you used post method. I stored it in a variable cause personally typing a variable name is easier to me then typing out $_GET or $_POST method. Hope this helps and makes sense if you have any problems let me know
  4. Not sure if this is the right section to put this in but since I be using PHP on my page maybe it fits here. What I want to do is display a blog on my site, not using wordpress themes and what not I designed my own site and want to use it G.D. IT! So I started searching the net on how to do this as usual couldn't really find what I'm wanting to do except this link..... http://blogging.nitecruzr.net/2007/06/adding-your-blogger-blog-to-your-non.html This part of the page is exactly what I want to do: So I signed up for blogger at blogger.com and went to feedburner and set me up on that. But now I'm stuck I dont really understand how I'm suppose to now display my blog feed on to my site. I been searching for tutorials articles anything how to do this with blogger and feedburner to show me how to accomplish this but came up with nothing. Can anyone point me in the right direction to do this? Do I need to set up an rss feed or something? Not sure how to do that yet either but really want to learn how to do this so any help will be very appreciated. Again sorry if I put this in the wrong section.
  5. can i add something like this to the query? $result = mysql_query("SELECT COUNT(id) AS numRows FROM table WHERE id='5' && equipped='equipped'"); $numRowsTotal = mysql_result($result, 0, 'numRows'); Well you can pretty much add anything to your code as long as what your adding exisit in the database other wise just spit back errors. I'm really not sure what your trying to do or what this script does so its hard for me to figure out exactly what your trying to accomplish. With that being said the sample code I gave you was assuming you where just trying to count the number of records in a database table. Therefor the code example is an sql query that contacts the database and gets the number of records in that table and stores them in a variable. So say your table has 5 records you run that query statement the value that is stored in the variable $numRowsTotal would be 5. Until more records are stored in the database then it would reflect that number. In your post where you changed the code to say WHERE id='5' should work but it would only return 1 record that record being the table id field that is 5 and if there is no id 5 nothing will return and the value you the variable that is storing it will be 0. So I really dont see a point of including a WHERE clause when trying to get the total number of records in a table. Now a WHERE clause would work if for example in your table you have rows that have the same information. say for example you have the word "APPLE" in a field called fruit, say you have a total of 10 records in the table but "APPLE" areas in 4 out of the 10 records. So you would use a WHERE fruit = "APPLE" to pull out just the number of records for the word APPLE then it would store 4 in the numRowsTotal varaible. Hope that helps explain a bit better sorry If I cant help more if you explain what your trying to do a bit more I might be able to be more insightful or hopefully someone else sees this and chimes in that knows more then me to help. I know the feeling being stuck on something like this. I think we all been there.
  6. I did something similar to this a while ago where I would allow user to upload images to my site and it would create a folder with the username and all their images would be stored there. I did this by using the php mkdir function which would create a folder. Unfortunaltly I can not find the code I used but I remember I had some code that would check to see if the directory excisted first and if so it would just place a file there if not it made the directory first then continued to upload the file. Here is the syntax on the mkdir function. http://php.net/manual/en/function.mkdir.php Also another useful function I remember I used when people where deleting files from their folder was the unlink function here is the link for that. http://php.net/manual/en/function.unlink.php Hope this gets you started I will look for the code I used before and when I fined it will post back if you still need help.
  7. Well as my understanding of how Search Engines work, and I could be wrong because it seems the rules in which search engines gather information change day to day. I don't think it matters that your information is stored in the database, because when the page loads from someone visiting a little spider bot crawls the page and stores the information on that page that was pulled from your database, including the link in its own little database. So I guess if your site is popular enough and is ranked high enough it the search engines database when someone does a search that has relative information to your site it will show up. Now a lot of what gets stored or noticed by the search engine is based on how you write your html code and what not. I would do some reading on Search Engine Optimization (SEO) and your probably have a better understand of how to code your pages to make it SEO friendly. Again dont take what I say word for word I'm not an expert on SEO yet but sort of understand whats going on. Hope this helps a bit.
  8. Well to explain it the $curIndex++ in your first reply is necessary that relates to when the thumbs are loading on the page. To explain what value that is holding better is basically its holding the value of index the current index its on so when the page with the thumbs load the first image has an index of 0 so the first time it goes through the loop the $curIndex has a value of 0 the when it gets to $curIndex++; its adding 1 which means the next image thumb being loaded has a value of 1 then the 3rd thumb will have a index of 2 and so on. That has nothing to do with my problem. Thats just setting the index value that will be passed in the url to know which image to show. The second post I see what you did and thats not really helping me at all. My problem is not with how the images are being displayed on the thumbnails page really the problem is the page links at the top of the page. For example when the page loads its displaying 6 thumbs per page the first image has an index value of 0 and the 6th image has an index value of 5. Now if you click page 2 everything stays in order the index values being passed increase by 6 based on the the current index value of the first image on the page which on page 1 is 0 + the number of images being displayed per page which in this case is 6 so 0 + 6 = 6. So on page two the first image on that page has a value of 6 which is how it should be. Now if you go from page 2 to 3 everything works as explained above it takes the index value of the first image passes through the link which is 6 and adds another 6 to it representing the number of images to be displayed so the first image on the 3rd has an index variable value of 12. And as you continue on clicking the next page this way in order everything works fine. Also you will notice the < (goes back 1 page) and >(goes forward 1 page) this works fine as long as you HAVE been going through the pages in order. Now the issue I'm having if you on page 1 and skip page 2 and click on page 3 the Index value of the first image on the page is wrong its still adding 6 to the value when I need it to make adjustments for those that are skipping pages in this case It needs to add 12 instead of 6. This also causes problems if you say again skip page 2 and click on page 3 and then decided to click the page 2 link or click the > or < link the images on the thumbnail are displaying in the correct order but the value that the variable hold index is wrong. In most cases its still adding 6 rather then taking the current index value for the first image on that page and subtracting. Now I know somehow to make the adjustments I need to adjust for page skipping by taking the current page I'm on say I start on page 1 and want to go to page 3 I need to some how figure out the difference which would be 2 (3-1 = 2 page difference) then take the current index of the first image on page 1in this case which is 0 and multiply it by 6(the number of images per page) times the difference in pages I'm navigating which is 2 in this case which would put me at the correct index value of the first image on page 3 which would be 12. And need to figure out away to do something similar if I go from page 1 to page 3 then go back to page 2. The index value being passed has to be correct to display the proper image when you click to see the full image. cause index is holding the information stored in the database which includes the path to each image. Does this make sense what I'm trying to do? What I need to do is on the tip of my brain but I'm just having trouble getting the right syntax for it and getting placed in the proper spot in my code. Again to see whats going on here is the link. http://digitalgallery.cbstrauss.com/gallery.php To see more clearly what I'm talking about: 1) load the page and then navigate in order from page 1 to page 2 to page 3 and so on. you can even click the <(back link) >(forward link) and see its fine. Click on a thumb to see the correct full size image is being displayed. Also look in the status bar at the bottom of the page as you hover over an image or one of the page links and see what values are being passed. 2)Now load the page again and go from page 1 to another page other then 2, skip around page numbers and with the < > links. Then click on the large images check the values being passed in the url and status bar and see they are not matching up.Even though on the thumbnail page the images are in the right order their index value is not correct causing the wrong image to load when you click the full size image and when you go back its adding instead of subtracting. Again I feel I'm close to figuring this out but just cant figure out what I need to do to get it to work properly so any examples or ideas I really appreciate it. I spent two days working on this script and this seems to be the last issue to sort out before I'm done.
  9. Are you trying to get the number of records in the database with recordcount? if so you can do something like this to get the number of records in a table. $result = mysql_query("SELECT COUNT(id) AS numRows FROM table"); $numRowsTotal = mysql_result($result, 0, 'numRows'); COUNT(id) the (id) can really be any table field name in your table but id is probably the most commenly counted to retriveve the number of records in a table. then just store that number in a variable name of your choosing in this cause it stores the number in my variable I called $numRowsTotal. Hope thats what you were looking to do if not please explain further and I will try to help more.
  10. Tried to sleep on this problem and come back with a fresh head this morning and still drawing a blank to getting my navigation to work properly. Here is the link to what I'm working on. http://digitalgallery.cbstrauss.com/gallery.php if you click the page links you see what I'm talking about you start on page one and if you click the next page it works fine. If you click the next page after that is fine, you can see in the url the images index variable is increasing by 6 in this case correctly. Now if you click a page number lower then what your on you see it still adding 6 instead of subtracting and that's what I'm trying to fix I'm using the same code as I posted above and this the last thing I need to fix (I think LOL) to complete this project. Anyone have an Idea of how I can get it to subtract correctly when going backwards?
  11. I been working on a new gallery script and have everything working perfectly except 1 little problem with the pagination and clicking on a page number to go back. I need the link to pass a variable called index to make sure if Im displaying 2 images per page on the first page the first image is index 0 next is 1. Then when I click the page 2 link it takes the current index which in this case is 0 (which 0 is the first image in the index and first displayed on the page) and adds 2 to the variable (because I'm displaying 2 images per page) so on page 2 the first image has the correct index of 2. This all works fine as long as I go forward. My problem is say I went from page 1 to page 2 my current index of the first image on page 2 is 2, but if I want to go back to page 1 by clicking the page 1 link its adding 2 again to my index variable being passed messing up my index order and setting my index to 4 instead of 0. I know I need to somehow make it so it subtracts in this situation just having a hard time figuring out how I need to change my code to do this. Here is my code: <?php // Connect to a database // Get the current index from of the URL. $curIndex = isset($_GET['index']) ? (int) $_GET['index'] : 0; //Pagenation Code // Get Number of Rows in Table $result = mysql_query("SELECT COUNT(img_id) AS numRows FROM gallery") or die(mysql_error()); $numRowsTotal = mysql_result($result, 0, 'numRows'); // Number of items to display per page $rowsperpage = 2; // Find out total number of pages $totalpages = ceil($numRowsTotal / $rowsperpage); // Get the current page or set defult page. if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // type cast var as int $currentpage = (int) $_GET['currentpage']; }else{ // Default Page Number $currentpage = 1; } // if current page is greater then total number of pages set the current page to last page if($currentpage > $totalpages){ $currentpage = $totalpages; } // if current page is less then first page set the current page to first page if($currentpage < 1){ $currentpage = 1; } // offset the list based on the current page $offset = ($currentpage - 1) * $rowsperpage; // Create Pagenation Links // Range of number of links to show $range = 3; $nextIndex = $curIndex + $rowsperpage; $prevIndex = $curIndex - $rowsperpage; // if not on page 1 dont show back links if ($currentpage > 1) { // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage&index=$prevIndex'><</a> "; } // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x&index=$nextIndex'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage&index=$nextIndex'>></a> "; } // end if // End Pagenation Code ?> <br /> <?php // display contents from database // Get Data from DB $result = mysql_query("SELECT * FROM gallery ORDER BY img_id DESC LIMIT $offset, $rowsperpage"); if(!$result){ echo "MYSQL ERROR: ".mysql_error(); } // Display results while they are avaiable while($row = mysql_fetch_assoc($result)){ stripslashes(extract($row)); ?> <!-- Display Thumbs --> <a href="gallery.php?index=<?=$curIndex;?>"<img src="gallery/art_tn/<?=$img_tnName;?>" alt="<?=$curIndex;?>" /></a><br /> <?php $curIndex++; } ?> My question is what do I need to change in my code to get this pagnation navigation to work properly when going back and changing my index variable being passed in the link to subtract rather then add when I click a page number to go back 1 page or I click back more then 1 page back from my current page.
  12. I posted a subject last week and got the help on figuring out how to make next and previous button for an image gallery. Here is the link to that topic. http://www.phpfreaks.com/forums/index.php/topic,275729.msg1304633.html#msg1304633 Now on to my current problem I'm trying to add that logic to my current gallery script, but I'm obviously not understanding something. Obviously the next and previous buttons are working as well as they can, except they are displaying the right images, When I hit the next button or previous button it just loads the current image again then will cycle through the others but at times skips images are displays them out of order. Here is my code Im working with I will try to break it up and comment where need be. This is basically the main page that shows the thumbnails, you click on thumb and takes you to the full size image this works fine. Showing in case there is something I'm missing to make the second part work. include $_SERVER['DOCUMENT_ROOT'].'/classes/clsPaging.php'; // Connect To DB // Get the current index from of the URL. //Set Page Links if(!isset($_GET['page'])){ $_GET['page'] = 1; } $page=$_GET['page']; $limit = 2; $num_records = @mysql_query("SELECT COUNT(*) FROM gallery") or die (mysql_error()); $total = mysql_result($num_records,0,0); $link = 'gallery.php?page='.$_GET['page']; // Work out the pager values $pager = Pager::getPagerData($total,$limit,$page); $offset = $pager->offset; $limit = $pager->limit; $page = $pager->page; // Query Database To Get Screen Shots $sql = @mysql_query("SELECT * FROM gallery ORDER BY img_id DESC LIMIT $offset,$limit"); if(!$sql){ echo "Error With MySQL Query: ".mysql_error(); } ?> <td class="contentStatic" valign="top"> <div id="gallery"> <div class="deftxt" style="padding-bottom:10px;" align="center"> <? include $_SERVER['DOCUMENT_ROOT'].'/inc/paging_system.php'; ?> </div> <!-- Thumbs Section --> <table width="100%" border="1" bordercolor="#000"> <tr> <? $loopvar = 0; while($row = mysql_fetch_assoc($sql)){ stripslashes(extract($row)); if($loopvar % 2 == 0){ ?> </tr><tr align="center"><td class="galleryItem"><a href="/imageview.php?img_id=<?=$img_id;?>&page=<?=$page;?>"><img src="/gallery/art_tn/<?=$img_tnName;?>" class="imgLink" /></a> <br /> <?=$img_title;?></td> <? }else{ ?> <td class="galleryItem"><a href="/imageview.php?img_id=<?=$img_id;?>&page=<?=$page;?>"><img src="/gallery/art_tn/<?=$img_tnName;?>" class="imgLink" /></a><br /> <?=$img_title;?></td> <? } $loopvar++; } ?> </tr> </table> <!-- End Thumbs Section --> </div> </td> This is the code that displays after click the thumb to show the fullsize image <? //Database Connetion Here. $img_id = $_GET['img_id']; $page = $_GET['page']; // Get Image From Databasee $sql = mysql_query("SELECT * ,date_format(img_date,'%M %D, %Y') as img_date FROM gallery WHERE img_id='{$_GET['img_id']}' LIMIT 1"); if(!$sql){ echo "Error performing query: ".mysql_error(); } $row = mysql_fetch_assoc($sql); stripslashes(extract($row)) ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Artwork Of Chris Strauss - <?php echo $img_title;?></title> <link rel="stylesheet" href="styles.css" type="text/css" media="all" /> </head> <body class="siteBg"> <div id="page" class="page"> <table width="1000" cellpadding="0" cellspacing="0" border="0" bordercolor="#FFFF00"> <tr> <td class="galleryHeader"> </td> </tr> <tr> <td><table border="0" cellpadding="0" cellspacing="0"> <tr> <td class="contentBg2"> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td align="center" > <img class="imageItem" src="/gallery/art_large/<?=$img_filename;?>" alt="<?=$img_title;?>" title=""> </td> </tr> <tr> <td align="center" class="title"><?=$img_title;?></td> </tr> <tr> <td> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <?php // Get the current index from of the URL. $curIndex = isset($_GET['index']) ? (int) $_GET['index'] : 0; // Get the total number of rows in the table. // We will use this information to determine the $nextIndex. $result = mysql_query(" SELECT COUNT(img_id) AS numRows FROM gallery ") or die(mysql_error()); $numRowsTotal = mysql_result($result, 0, 'numRows'); if ($curIndex + 1 >= $numRowsTotal) { $nextIndex = 0; } else { $nextIndex = $curIndex + 1; } if($curIndex == 0){ $prevIndex = $numRowsTotal - 1; }else{ $prevIndex = $curIndex - 1; } // Get a single record out of the table from the $curIndex position. $result = mysql_query(" SELECT * FROM gallery ORDER BY img_id DESC LIMIT $curIndex, 1 ") or die(mysql_error()); if (mysql_num_rows($result) > 0) { $row = mysql_fetch_assoc($result); // Display its information for testing purposes. echo "<pre>"; print_r($row); echo "</pre>"; echo $nextIndex; } ?> <td align="center" class="linkClass1" width="33%"><a href="?index=<?= $prevIndex;?>&img_id=<?=$img_id;?>&page=<?=$page;?>">Back</a></td> <td align="center" class="linkClass1" width="33%"><a href="/gallery.php?page=<?=$page;?>">go back</a></td> <td align="center" class="linkClass1" width="33%"><a href="?index=<?= $nextIndex;?>&img_id=<?=$img_id;?>&page=<?=$page;?>">Next</a></td> </tr> </table> </td> </tr> </table> </td> </tr> </table> <tr> <td><img src="images/footer_19.jpg" alt="" title="" /></td> </tr> </table> </div><!-- End Page Div --> </body> </html> Now the first set of php code at the top obviously taking the img_id so it knows what image to get out of the database and the page variable just to keep track of the last page you where on for the go back button. Now Here is where my problem comes in at the bottom (the last set of PHP code) is the code Im trying to implement into from my last topic to give the ability to just start going through the large view images if the user wishes rather then go back to thumbnail page. now it seems my problem is my img_id and nextIndex/curIndex/prevIndex variables are not matching up. and I'm trying to figure out away to get the img_id value to match the nextIndex and prevIndex value so when you click those links they will go to the right image. I realize the reason it goes to the same image the first time you click is cause the value being passed is actually the current img_id. Anyone have an Idea of what I need to do to get my code working or do I have a problem that is just impossible to do? Thanks in advance for any ideas you might have.
  13. It took me a while to figure out how to make it work backwards with a back button and when on the first record to go to the last when pressed but I got it Working backwards kind of sucks sometimes but I got it to work. But just stepping through the next code line by line figuring out what it did to move forward and back to the first record I figured out where it needed to be changed to make it go in reverse. I used something Like this for back link: if($curIndex == 0){ $prevIndex = $numRowsTotal - 1; }else{ $prevIndex = $curIndex - 1; } Haven't ran into any problems with let me know if you see a flaw or something in my back code if not I will mark this as solved and hopefully someone can learn from it as well. Thanks again for your help, the Idea I had involved taking the id out of the database and storing it an array then using that which would of been a lot more coding and lot more un needed headaches I could of avoided. Thanks again.
  14. Okay Im having a little complication figuring out exactly what the currentIndext and nextIndex relate to. Do I need to define them somewhere with an initial value of 0 or do I need an array with the stored ID from the database table that relates to them?
  15. Thanks this is a start for me to play around with, I'm trying to do this with a image gallery so when they are viewing the the larger image and not the thumbnail there be these next previous links to go on to the next large image rather then have to go back to the thumbnail page. So basically I'm just trying to find a way to modify and improve my existing code to make it more end user convenient. Like I said I will play around with your example and report back my results or if I run into any other questions.
×
×
  • 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.