|
|
|
SQL query with HTML link
|
Original Message
|
Name: Tope
Date: April 22, 2004 at 02:44:14 Pacific
Subject: SQL query with HTML link OS: WinXP CPU/Ram: 2.53gHZ/512RAM
|
Comment: I've been going nuts on this one as well. As you may remember, the last thing to drive me crazy was trying to order my results from MySQL. This time it's trying to make a query to the database from a link on my webpage. I can't figure out how it might be done. I tried making doing this: $A = mysql_query("SELECT * FROM A ORDER BY Name", $link); print "<td align=center>A</td>"; That did not work. I tried putting quotes around the $A as well and could not get it to work. When I click on that link it links to Resource%20id%20. I was told be a tech support person that what I had done would work. I can't seem to find any examples online for this. Any ideas? <><><>Poet<><><>
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: anonproxy
Date: April 22, 2004 at 10:51:30 Pacific
Subject: SQL query with HTML link |
Reply: (edit)Tech support for your programming? I assume the only problem with the link is the addition of encoded symbols like %20. That shouldn't be a problem, because that represents a space character. They are the same thing for a browser. You can experiment and find this to be true. You might consider trying a different approach to creating your strings. Generally, it's unnecessary to store redundant and instance specific data in the database (like http://). Instead, it's a common practice to simply store file names and include a configuration script with some predefined variables. Therefore a lot of programmers build link strings like this: $protocol = 'http://'; $domain = 'www.domain.tld/'; $db_link_result = 'dir/filename.ext'; $db_link_text = 'Click Here!'; $link = $protocol.$domain.$db_link_result; $final_link = "[bracket]a href=\"" . $link . "\" [bracket]" . $db_link_text . "[bracket]/a[bracket]"; echo $final_link; /*Replace [bracket] with < or >, respectively. This forums parser interferes with display those*/
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: Tope
Date: April 22, 2004 at 11:11:59 Pacific
Subject: SQL query with HTML link
|
Reply: (edit)I forgot to change my "<" and ">" last night. Part of my example got cut out. It should be: $A = mysql_query("SELECT * FROM A ORDER BY Name", $link); print "[td align=center][a href= $A target=\"side\"]A[/a][/td]"; I did try doing the variable like \" .$A. \" That didn't work either. I'm trying to query my database from a link.When I click on the above link it just takes me to Resource%20id%20. Not the results that are suppose to be coming from my database. <><><>Tope<><><>
Report Offensive Follow Up For Removal
|
|
Response Number 3
|
Name: anonproxy
Date: April 22, 2004 at 13:31:46 Pacific
Subject: SQL query with HTML link |
Reply: (edit)mysql_query() returns a resource ID, not any data. That means for you $A holds an ID, which is linked to rows that were pulled from the database. To operate on this information, pass $A as an argument to functions like mysql_fetch_array(), which will process the data into an associative array. You can find what you want in the array and isolate data from there. Check the online manual for examples under mysql_fetch_array().
Report Offensive Follow Up For Removal
|
|
Response Number 4
|
Name: Khalid
Date: April 22, 2004 at 13:35:30 Pacific
Subject: SQL query with HTML link |
Reply: (edit)You are trying to link a query? Never heard of that. I think you'll have to link to a php-script that executes the query for you. The webserver doesnt 'know' what it should do with this query since you are not requesting any file (and that is the only thing a webserver is capable of; serving files). Anonproxy shows a simple way to request for a file, but the 'A$'-variable of you doesnt contain one. Besides that, you dont want a script to execute a query wich is formulated in the address / link. Any user with know-how of sql -query's and/or php can feed the script qith malicious coding to corrupt your database.
Report Offensive Follow Up For Removal
|
|
Response Number 5
|
Name: Tope
Date: April 22, 2004 at 23:36:10 Pacific
Subject: SQL query with HTML link
|
Reply: (edit)Ok, I see what you mean. It looks like I can do it by linking to a PHP script to make the query for me. I've been looking around and saw that on a lot of sites there are PHP scripts that have links with ""?action=show&id=" after them. I can't find any info on doing this. It looks like it could be quite useful if I could understand it. You wouldn't happen to know where I could find info on that? Man I'm such a newb with this. :-\ <><><>Tope<><><>
Report Offensive Follow Up For Removal
|
|
Response Number 6
|
Name: Khalid
Date: April 23, 2004 at 10:44:10 Pacific
Subject: SQL query with HTML link |
Reply: (edit)Buy a good book about programming with PHP / MySQL. It is well worth your money. It is quite impossible to explain the very basics about sending variables through an url since it will only stirr up new questions etc etc. Before we know it, we have a very long topic with a disorganized attempt to learn you PHP. ;-)
Report Offensive Follow Up For Removal
|
Use following form to reply to current message:
|
|

|