PHP getting data from mysql database for the Query string variable -
What I would like to do here; I am passing an encoded data as a query variable for my webpage, then in my php page, I am decoding data and checking my database the same. The code I'm using is shown below:
& lt ;? Get ID from Php // URL $ Id = (isset ($ _GET ["id"]) & amp; empty! ($ _GET ["id"])? $ _GET ["id"]: "") ; // If "id" is not empty, go ahead if (! Id ($ id)) {$ id = base64_decode ($ id); Global $ wpdb; $ Res = $ wpdb- & gt; Query ("SELECT * FROM S_redirect WHERE source =". $ Id); $ Tot = count ($ res); Copy $ tot "records."; ($ I = 0; $ i & lt; Count ($ res); $ i ++) {ebay $ res [$ i] - & gt; For ID; } Go out; } Else {resonant "id not"; Go out; }? & Gt; I have a record in my database The above code says "1 record" I'm not sure how to get the value of the field in that row I have 3 columns, They are id, field 1 and field 2.
Please
BTW, I'm trying to get into my WordPress blog Thank you everyone for your suggestions I tried your suggestions and here are my results:
$ res = $ wpdb-> Query ("SELECT * FROM S_redirect WHERE source =". $ Id); $ Tot = count ($ res); Copy $ tot "records found." "& Lt; / br & gt;"; It says that 1 record is found.
$ res = $ wpdb-> Get_row ("SELECT * FROM S_redirect WHERE source =". $ Id); $ Tot = count ($ res); Copy $ tot "records found." "& Lt; / br & gt;"; It says that 0 records have been found.
$ res = $ wpdb-> Get_results ("SELECT * FROM S_redirect WHERE source =". $ Id); $ Tot = count ($ res); Copy $ tot "records." "& Lt; / br & gt;"; It says that 0 records are found.
while ($ line = mysql_fetch_array ($ res)) {echo $ row [0]; } If I use mysql_fetch_array, Warning: mysql_fetch_array () uses: supply logic A legitimate MySQL result resource / home / myfolder / mytheme / Index.php on line 38
line 38 while ($ line = mysql_fetch_array ($ res)) {.
I'm trying to complete: I have a WordPress blog, all the above code goes to my index.php. I will pass a product ID through my index.php query query string. I have created a new table called S_redirect in my WordPress database. I will retrieve the value of the query string variable id and check it in my database table. If the record is present, retrieve one of the column values (the URL of the product) from that table row and redirect to that product URL. If the record is not present then redirect to home page is hopeful that it helps everyone understand what I am doing.
$ wpdb , it is expected that it is a WordPress This will help you:
update use the count () to get the number of rows Do; Use (any () because it is a property, not a function). Always returns 1 for any non-zero value, which does not recognize it as "mathematical" value (i.e., array and some objects), so it will probably always give your code 1. $ root = $ wpdb-> Num_rows; ===== If you run your query with get_results () instead of with query () , then you Loop through the results like this: foreach ($ res as $ line) {echo $ row-> id; } Finally, I think your code looks like this:
$ res = $ wpdb-> Get_results ("SELECT * FROM S_redirect where source =". $ Id); $ Tot = $ wpdb- & gt; Num_rows; Copy $ tot "records."; Forex Currency ($ res as $ line) {echo $ row-> Id; } Disclaimer: This is untested, as I have never used WordPress, how do I understand it from the above mentioned documentation. Hopefully this will take you to the right path at least.
Comments
Post a Comment