Jump to content

making returned values unique?


therelelogo

Recommended Posts

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

Link to comment
Share on other sites

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  :P

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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]\" />";
?>

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

WOW, seriously, WOW  :D

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  ;D double win

Link to comment
Share on other sites

:'( 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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.