slashpine Posted August 17, 2006 Share Posted August 17, 2006 I am not sure this is doable but then it again it may be easy...that's why I'm here, I don't have a clue...I am looking for a way to create (syntax) a variable (row id) in a generic link that can be placed in a database column that when displayed (in a browser) with the other columns in any particular row...the link will end up looking something like ths:../foo.php?query=123 Where "123" is the id for that particular row.i.e., I want to be able to insert the the same "link" in all the rows but in the returned display they all need to link to ../foo.php?query=$id (where '$id' will be the actual row id )hope this is doable...? Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/ Share on other sites More sharing options...
Jenk Posted August 17, 2006 Share Posted August 17, 2006 Yes it is.[code]<?phpwhile ($row = mysql_fetch_assoc($result)) { echo '<a href="foo.php?=' . $row['id'] . '">Clicky clicky</a>' . "\n";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76249 Share on other sites More sharing options...
slashpine Posted August 17, 2006 Author Share Posted August 17, 2006 thanks for the reply...what I am looking for the is the exact syntax of the "link" that gets placed in the database cell...i.e:I thought it should look something like this: [b]<a href="h**p://foo.com/foo.php?query=$id">click here</a>[/b]but this does not work...it does not capture the row id Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76262 Share on other sites More sharing options...
ToonMariner Posted August 17, 2006 Share Posted August 17, 2006 why store all that in the database?Just echo out the link as jenk suggests... Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76267 Share on other sites More sharing options...
slashpine Posted August 17, 2006 Author Share Posted August 17, 2006 can you tell me what to put in the database cell so that when results of that particular row are displayed it displays a link that executes another query based on the id of the row that the link originall resided? Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76282 Share on other sites More sharing options...
Jenk Posted August 17, 2006 Share Posted August 17, 2006 [code]<?php$query = "SELECT * FROM `yourtable` WHERE `id` = '" . mysql_real_escape_string($_GET['query']) . "'";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76288 Share on other sites More sharing options...
slashpine Posted August 17, 2006 Author Share Posted August 17, 2006 that does not do anything...I need something that is going to put a hyperlink in the initial results displayis this possible? Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76299 Share on other sites More sharing options...
slashpine Posted August 17, 2006 Author Share Posted August 17, 2006 thanks for the replies...I probably did not do a good job of citing what I need here... I don't want to have to alter any existing php scripts that presently query my db... I am looking for something (described above) that can be placed in a cell of db that will reflect the id of the row in which it resides.... when displayed, the row id is parsed into the "link"again...I am not looking for a php script... I am looking for the correct syntax (if it exists) of a hyperlink that will do as said. Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76309 Share on other sites More sharing options...
slashpine Posted August 17, 2006 Author Share Posted August 17, 2006 so this is not possible? >:(thanks for the efforts anyway Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76331 Share on other sites More sharing options...
akrytus Posted August 17, 2006 Share Posted August 17, 2006 [quote]I thought it should look something like this: <a href="h**p://foo.com/foo.php?query=$id">click here[/url][/quote]syntax using php:[code]echo "<a href=\"http://foo.com/foo.php?query=$id\">click here</a>"[/code]Is that what you are looking for? Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76335 Share on other sites More sharing options...
slashpine Posted August 17, 2006 Author Share Posted August 17, 2006 something to that effect is what I am looking for but that does not work it just prints "...=$id"it does not parse the actual row id...I have also tried using ...foo.php?query=.$id['id'].">click here</a>"nothing works...that is why I am here... Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76345 Share on other sites More sharing options...
akrytus Posted August 17, 2006 Share Posted August 17, 2006 [quote]...foo.php?query=.$id['id'].">click here[/url]"[/quote]Yeah I thought about that earlier. You use the wrong syntax, no quotes inside the array $id[''], you do indeed need the brackets, you were missing them earlier, although I wouldnt use brackets here becuase it is easier to parse the info out yourself, like:[code]foreach ($id as $value){ echo "<a href=\"http://foo.com/foo.php?query=$value\">click here</a>"}[/code]This will find each element of the array $id and parse it out into a new single variable $value. Then you can use it as you were.Does that help? Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76350 Share on other sites More sharing options...
slashpine Posted August 17, 2006 Author Share Posted August 17, 2006 no I don't think it does... whatever I put into the cell that gest displayed running the original query has to start with " <a herf=" to get displayed as a hyperlink...how do I ge the this to get the row id ? Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76357 Share on other sites More sharing options...
akrytus Posted August 17, 2006 Share Posted August 17, 2006 Ohh so you dont wont to echo it, just save it into the array?$i=-1;while{$i < $number_of_loops_you_want){ $i++; $id[$i]="<a href=\"http://foo.com/foo.php?query=$value\">click here</a>"}Like that? Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76361 Share on other sites More sharing options...
HeyRay2 Posted August 17, 2006 Share Posted August 17, 2006 Can you post the code you use to query your database for your results.That will help us better understand what information you are looking to print out for each result, and then we can make suggestions on how to format that result printing for a hyperlink. ;) Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76367 Share on other sites More sharing options...
slashpine Posted August 17, 2006 Author Share Posted August 17, 2006 I am sorry I can't seem to make myself clear on this....what I am looking for is the HTML/php code that when placed in a database row it will be displayed as link to a script that runs a second query on the same database based on the id of the row that HTML code originall resided...This (row id) must be a variable so the (HTML/php) code can be placed on every row (50k+) but when displayed will parse the row id ($variable) as unique to the row. Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76377 Share on other sites More sharing options...
HeyRay2 Posted August 17, 2006 Share Posted August 17, 2006 I think we've got a grasp on what you're trying to do. I just wanted to see the code you are using to query the database, that way I know what data we need to print out. However, let's just make an example database table called "companies".[b]companies[/b]company_idcompany_namecompany_descetc...When we run the first query, we'll just grab the company names and IDs for printing a big list:[b]company_list.php[/b][code]<?php// Query for all companies$sql = "SELECT company_id, company_name FROM companies ORDER BY company_name";$result = mysql_query($sql) or die("Error Querying Companies: ".mysql_error());?>[/code]Then we'll print out a row for each company, echoing the company name, and using the ID in a hyperlink to a page that will show the details for that specific company only (company_detail.php).[b]company_list.php[/b] continued....[code]<?php// Print a table for company resultsecho '<table border="1" width="100%"> <tr> <th>Company Name</th> <th>Company Details</th> </tr>';// Print the resultswhile($row = mysql_fetch_array($result)){ echo '<tr> <td>'.$row['company_name'].'</td> <td><a href="company_detail.php?company_id='.$row['company_id'].'">Details Link</a></td> </tr>';}// Close the tableecho '</table>';?>[/code]Now that we have our company list page with link to each company, we can make a detail page, and thelinks we created will pass in the company ID, so that we can pull information for just that company.[b]company_detail.php[/b][code]<?php// Get the company ID from the URL$company_id = $_GET['company_id'];// Query for the company details$sql = "SELECT * FROM companies WHERE company_id = ".$company_id." LIMIT 1";$result = mysql_query($sql) or die("Error Getting Company Details: ".mysql_error());// Print the Company Detailsecho '<table border="1" width="600"> <tr> <td>Company: '.$row['company_name'].'</td> </tr> <tr> <td>Company Description: '.$row['company_desc'].'</td> </tr> <tr> <td>Other company info goes here...</td> </tr> </table>';?>[/code]That should get you the basic functionality. Now you can pretty it up and make it your own! ;) Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76390 Share on other sites More sharing options...
slashpine Posted August 17, 2006 Author Share Posted August 17, 2006 I really do appreciate the efforts but this is not what I am seeking....My whole point is not having to edit or ammend the existing query scripts... thus the want for something (hyperlinked text) that I could put into existing row cells that would capture the id of the row in which it resides...and reflect this (unique row id) in the initially displayed link... Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76409 Share on other sites More sharing options...
redarrow Posted August 17, 2006 Share Posted August 17, 2006 bad advice sorry if going to use the $_GET // Get the company ID from the URL$company_id = $_GET['company_id'];use it this way okset the session first$_SESSION['company_id']=$row['company_id'];the linka href="company_detail.php?company_id=company'">Details Link</a>code correct wayif ($_GET['company_id']=="company")){$company_id = $_SESSION['company_id'];}hope that clears that up ok mate. Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76416 Share on other sites More sharing options...
slashpine Posted August 17, 2006 Author Share Posted August 17, 2006 sorry but I can't make any of that work (too many errors)also the "link" does not parse the row id it only prints :?id=id Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76440 Share on other sites More sharing options...
HeyRay2 Posted August 17, 2006 Share Posted August 17, 2006 [b]redarrow[/b], there is no reason to pull the company ID into a $_SESSION variable, because the value only needs to exist on [b]ONE[/b] page.So, apart from me not adding data validation code (which I excluded for reasons of simplicity in my example) [b]no[/b], my suggestion was not bad advice, but commonly used code for this type of situation.[quote author=slashpine link=topic=104631.msg417613#msg417613 date=1155844726]I really do appreciate the efforts but this is not what I am seeking....My whole point is not having to edit or ammend the existing query scripts... thus the want for something (hyperlinked text) that I could put into existing row cells that would capture the id of the row in which it resides...and reflect this (unique row id) in the initially displayed link...[/quote][b]slashpine[/b], it seems that we're on different pages here. Can you post the code and queries you currently have so that I can get a better of what data we have to work with, and we can go from there. Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76448 Share on other sites More sharing options...
slashpine Posted August 17, 2006 Author Share Posted August 17, 2006 that is my point this quest has nothing to do with the current query scripts... what I am seeking has no bearing on the originating queries...Right now I have an empty column in an existing tabel row... what I am seeking is the an "<href" string that will parse the actual id of that particular row and return it to the string being displayed in the original results display...the main question of all this is...How do I get the actual row id from a variable that resides in that row? Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76461 Share on other sites More sharing options...
HeyRay2 Posted August 17, 2006 Share Posted August 17, 2006 Actually, it has everything to do with your current queries, because I can't help you determine what row data to parse if you can't provide me with what row data you are querying.Post your query code here so I can what data you are pulling, so then I can tell help you access that data. Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76511 Share on other sites More sharing options...
slashpine Posted August 18, 2006 Author Share Posted August 18, 2006 I do appreceiate all the efforts but the fact of the matter is....what I am seeking and what I have described in finite detail within this thread could theoretically be used in [u][b]ANY[/b][/u] databse that has an "id" field and one to contain the "link" string...regardless of any other fields.i.e.,...what I asked for is the [u]syntax of a string[/u] that when returned as a query result (regardless of any other columns being queried) so that said string would contain the id of the row where the string originally resided. Quote Link to comment https://forums.phpfreaks.com/topic/17848-need-assistance-with-variable-in-a-url/#findComment-76540 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.