therelelogo Posted June 23, 2010 Share Posted June 23, 2010 Hi once again, Okay, as far as i know this is the last code i need to be able to make my site how i want it, the problem is - i don't know if its even possible to do. when one of my pages pulls a query from a table, it presents it, in a table...thats fine. BUT, my site is supposed to be an "ebay" rip, so my question is...is there any way to assign some kind of "ID" to each returned result? i mean i could take this from MySql no problem but its a matter of how can i mod my code so that when the user clicks the result it passes it to another .php that searches and reuslts the product on a page? Basically, is there any way to give a potentially random (or sequential) result an ID that can then be clicked (href or simply a button at the end of the result) which takes the info to a seperate page? heres what i have so far: / / Make a MySQL Connection $result = mysql_query("SELECT * FROM adverts WHERE ad_type = 'premium' and category = 'Baby & Kids' ORDER BY item_id DESC") or die(mysql_error()); echo "<table border='3'>"; echo "<tr> <th>Item</th> <th>Price</th> <th>Seller</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['item_name']; echo $row['item_location']; echo "</td><td>"; echo $row['item_price']; echo "</td><td>"; echo $row['seller']; echo "</td></tr>"; } echo "</table>"; ?> and...just as an extra while im on the topic of retrieving results, obviously the code above orders the results left to right in a table format. can the above be changed to say show the item description below the item name on the left, and the rest of the info displayed on the right? not sure if i explained that very well...but its the first question im more concerned about. any help is appreciated Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/205646-making-returned-values-unique/ Share on other sites More sharing options...
tomtimms Posted June 23, 2010 Share Posted June 23, 2010 so you want a link like so <a href="yourpage.php?id=id_generated">Link Name </a> if you want to create a unique id for each row then just give your loop a counter and replace id_generated with your variable. Quote Link to comment https://forums.phpfreaks.com/topic/205646-making-returned-values-unique/#findComment-1076272 Share on other sites More sharing options...
therelelogo Posted June 23, 2010 Author Share Posted June 23, 2010 hi, thanks for the reply, you mean like count=0 item_name item_description item_price count=count+1 (loop) something like that? (obviously in actual code lol) and assign a href link to each "count"?, my problem there is i would need to carry that "count" number through to another PHP page to show further details of it - and this is my problem, i can't figure out a sensible way to carry it over :'( i like your idea of giving it an "ID" but it would mean manually coding what every ID would be and that seems an ineffective way to code - at least it would be the way i would do it lol Quote Link to comment https://forums.phpfreaks.com/topic/205646-making-returned-values-unique/#findComment-1076304 Share on other sites More sharing options...
tomtimms Posted June 24, 2010 Share Posted June 24, 2010 So let me get this straight, you want a link that will take you to a page that will show even more information based on the product that was selected? If that is the case then you need to have a field in your database that will contain an ID. Quote Link to comment https://forums.phpfreaks.com/topic/205646-making-returned-values-unique/#findComment-1076333 Share on other sites More sharing options...
therelelogo Posted June 24, 2010 Author Share Posted June 24, 2010 Hi, sorry, no thats not entirely what i want. i DO have a unique ID assigned to my table (increment (spell-check please)). What i want is... my code retrieves records based on my search so like get * fields from "my table" where item_category = "toys and games" something like that. now all the records for toys and games arent in order on my table so the unique ID's arent in order obviously. but i want them all to link to a php page (like advert_drilldown.php) but they ALL have to link to the smae page regardless. however when the advert_drilldown.php loads i want it to search again for more info from my table related to say "item_name" AND "user_id" or something, my problem is, how will "advert_drilldown" know which result the user clicked? and how can a variable to search for be passed to it? i mean i COULD make like 50 pages of the same thing and each one would search for $result number 1, $result number 2 etc etc etc but thats not efficient, and if there are more than 50 pages the link wouldnt work. i hope im explaining this right. just think like ebay, when you click any returned result it effectively takes you to the same page but with a different item shown. Quote Link to comment https://forums.phpfreaks.com/topic/205646-making-returned-values-unique/#findComment-1076697 Share on other sites More sharing options...
therelelogo Posted June 25, 2010 Author Share Posted June 25, 2010 i feel like i'm becoming one of those annoying users who only wants help and never gives... sorry. anyways, with regards to my above post, i have found what i think may be the answer to all my prayers!! (though its probabaly basic knowledge to you experts) this little code: <A HREF="standard_make_email_view.php?toname=Kevin"> Hi, I'm Kev </A> ...told you its nothing special lol. BUT can i pass this variable to a form? i want to pass it to the "toname" field of a form on the "standard_make_email_view.php" page. is this possible? please say yes :'( and if so, is it easy enough to do (suggestions on how would be appreciated) sorry if this breaks any bumping rules etc Quote Link to comment https://forums.phpfreaks.com/topic/205646-making-returned-values-unique/#findComment-1077256 Share on other sites More sharing options...
ejaboneta Posted June 25, 2010 Share Posted June 25, 2010 Wow... I think I might understand you... You should make one php script for an item details page. The unique auto-increment id in your table is the id you should use. Pass the variables in the URL <?php echo "<a href=\"details.php?id=$results[id]\">Train Set </a>"; ?> Use '$_GET[id]' in the php script so it knows what item Write another query to get the details based on the id. <?php $sql = "SELECT * FROM product_table WHERE id = '$_GET[id]'"; ?> As for your last post... if you want to pass that variable to the form, put the variable in the inputs value <?php echo "<input type=\"text\" name=\"toname\" value=\"$_GET[toname]\" />"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/205646-making-returned-values-unique/#findComment-1077264 Share on other sites More sharing options...
therelelogo Posted June 25, 2010 Author Share Posted June 25, 2010 hi, yes - you are completely getting me...im amazed, it barely made sense even to me lol okay.. so on your example...my first page looks like: <body> <A HREF="standard_make_email_view.php?toname=Kevin"> Hi, I'm Kev </A> </body> and the next page should have: <?php echo "<input type="text" name="toname" value="$_GET[toname]" />"; ?> have i understood that right? effectively when the link is clicked the textbox should say "Kevin"? ive tried it and it just says page could not be found and offers suggestions on google. I'm getting closer to the answer i can feel it, please ignore the initial question, because if i can get this answered i could probabaly solve my first badly-worded one on my own. thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/205646-making-returned-values-unique/#findComment-1077269 Share on other sites More sharing options...
ejaboneta Posted June 25, 2010 Share Posted June 25, 2010 if you are getting a page not found, then you might have mistyped the url or it doesn't exist. The target file should exist in the same folder if you do not specify another location. When you use double quotes, you need to escape all double quotes in the string with '\' or you will get errors. <?php echo "<input type=\"text\" name=\"toname\" value=\"$_GET[toname]\" />"; ?> Also, we don't capitalize html tags anymore. <a href="standard_make_email_view.php?toname=Kevin"> Hi, I'm Kev </a> Quote Link to comment https://forums.phpfreaks.com/topic/205646-making-returned-values-unique/#findComment-1077273 Share on other sites More sharing options...
therelelogo Posted June 25, 2010 Author Share Posted June 25, 2010 WOW, seriously, WOW yeah, i noticed after i posted my last post that i hadn't changed my directory...classic mistake i guess. and i wasn't sure about those "\"'s because i aint come across them before and i seemed to get an error the first time i put them in...but saying that i had also missed <?php ?> tags, im hungry and not thinking straight anyways, thank you SO much for your help, my code now does what i want it to do, and you also pointed me (or told me) in the right direction for my first post, so - very grateful to you, i can finally rest and go eat now double win Quote Link to comment https://forums.phpfreaks.com/topic/205646-making-returned-values-unique/#findComment-1077278 Share on other sites More sharing options...
therelelogo Posted June 25, 2010 Author Share Posted June 25, 2010 :'( i speak to soon :'( okay, so i followed what was said in an earlier post and used the following code: <?php // Make a MySQL Connection *removed* // Get all the data from the "example" table $result = mysql_query("SELECT * FROM adverts WHERE ad_type = 'premium' and category = 'Baby & Kids' ORDER BY item_id DESC") or die(mysql_error()); echo "<table border='3'>"; echo "<tr> <th>Item</th> <th>Price</th> <th>Seller</th> <th>View</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['item_name']; echo $row['item_location']; echo "</td><td>"; echo $row['item_price']; echo "</td><td>"; echo $row['seller']; echo "</td><td>"; echo "<a href=\"view_advert_specific.php?id=$results['item_id']\">View</a>"; echo "</td></tr>"; } echo "</table>"; ?> and i get the following error Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/a9203152/public_html/PHP-Login/advert_pages/baby_&_kids.php on line 131 the code worked fine before i tried adding the href line so its maybe just the way ive added it or something? also, just for info, it should link to this page: <?php // Make a MySQL Connection *removed* // Get all the data from the "example" table $result = mysql_query("SELECT * FROM adverts WHERE item_id = '$_GET[id]'") or die(mysql_error()); echo "<table border='3'>"; echo "<tr> <th>Item</th> <th>Price</th> <th>Seller</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['item_name']; echo $row['item_location']; echo "</td><td>"; echo $row['item_price']; echo "</td><td>"; echo $row['seller']; echo "</td></tr>"; } echo "</table>"; ?> which may have the same problem in it? Can anybody suggest something? this d**m code is driving me nuts. as always, help and advice appreciated Quote Link to comment https://forums.phpfreaks.com/topic/205646-making-returned-values-unique/#findComment-1077338 Share on other sites More sharing options...
therelelogo Posted June 25, 2010 Author Share Posted June 25, 2010 whoops.... the error should read: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/a9203152/public_html/PHP-Login/advert_pages/baby_&_kids.php on line 131 sorry for double post Quote Link to comment https://forums.phpfreaks.com/topic/205646-making-returned-values-unique/#findComment-1077339 Share on other sites More sharing options...
ejaboneta Posted June 25, 2010 Share Posted June 25, 2010 Well seeing as this isn't your whole script, I can't know whats on line 131. Can you post whats on this line? Quote Link to comment https://forums.phpfreaks.com/topic/205646-making-returned-values-unique/#findComment-1077345 Share on other sites More sharing options...
therelelogo Posted June 25, 2010 Author Share Posted June 25, 2010 oops. yeah its the line that reads echo "<a href=\"view_advert_specific.php?id=$results['item_id']\">View</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/205646-making-returned-values-unique/#findComment-1077347 Share on other sites More sharing options...
ejaboneta Posted June 25, 2010 Share Posted June 25, 2010 oh.... you used $results[id] instead of $row[id]. Quote Link to comment https://forums.phpfreaks.com/topic/205646-making-returned-values-unique/#findComment-1077353 Share on other sites More sharing options...
therelelogo Posted June 25, 2010 Author Share Posted June 25, 2010 oh yeah but no, that still didnt solve it, same error is still there, any other issues with that line? Quote Link to comment https://forums.phpfreaks.com/topic/205646-making-returned-values-unique/#findComment-1077354 Share on other sites More sharing options...
therelelogo Posted June 25, 2010 Author Share Posted June 25, 2010 sorry to double post YET AGAIN, but i've got it sorted now, needed to take the ' ' off item_id problem solved, case closed. thank you so much you have been a god send! truly thankful for your help Quote Link to comment https://forums.phpfreaks.com/topic/205646-making-returned-values-unique/#findComment-1077357 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.