Languages :: PHP :: Using ODBC results to pass variables through popups |
|||
| By: wokadoo |
Date: 21/06/2003 00:00:00 |
Points: 500 | Status: Answered Quality : Excellent |
|
Apologies for the confusing title.... But please read on. Need some help here (and urgently!). Let's say I have 1 table with the following fields - Code No. Logo 21111 Logo 1 21112 Logo 2 21113 Logo 3 These table exists in a database in SQL Server 2000, and I'm using PHP to pull these results out via odbc_result_all. Now with the table I'd like to add a field so that when the results come up, it displays the actual logo e.g. <img src="/logos/21111.gif"> Obviously 21111.gif would be pulled from the 'Code No.' field. Is this possible? Or do I need to create a new field? 2. The other thing I need to do - have a look at the following table. Code No. Song Title Pop-Up field 11111 Song 1 11112 Song 2 11113 Song 3 In the Pop-Up field, I will be inserting a JavaScript pop-up link which will do two things: - Open a new page, 'popup.php' which will contain the following details: Song Title: Song 1 Code No. 11111 (and other static information) - As well, I will be embedding a midi (e.g. 11111.wav) in popup.php. So in other words, I need to pass the code no. and song title as dynamic variables through the pop-up window via the GET method... (and do it for all 2000-odd songs in the DB). Is this possible with ODBC results??? Would appreciate any guidances or pointers. If anyone could offer me a solution I would forever be in your debt.... Thanks in advance. (bear in mind - the titles I've given to the fields are hypothetical and aren't the real field names, so they actually won't have spaces anyway) |
|||
| By: VGR | Date: 22/06/2003 05:00:00 | Type : Comment |
|
| 1) I assume you've some kind of : SELECT CodeNo, Logo FROM table1 WHERE... Then just do : SELECT CodeNo, Logo, CONCAT('<img src="/logos/',CodeNo,'.gif">') AS image FROM table1 WHERE... 2) UPDATE table2 SET popupfield=CONCAT('window.open(\'popup.php?SongTitle=',SongTitle,'&CodeNo=',CodeNo,'\',\'pipotitle\', \'width=800,height=600,left=40,top=40\');'); |
|||
| By: wokadoo | Date: 22/06/2003 10:31:00 | Type : Comment |
|
| Unfortunately CONCAT does not appear to work. Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\....\includes\inc.functions.php on line 220 Any ideas? |
|||
| By: wokadoo | Date: 22/06/2003 10:44:00 | Type : Comment |
|
| (update: just remembered CONCAT is MySQL only - can use CONCAT with UNION in SQL Server 2000 but nowhere else) |
|||
| By: wokadoo | Date: 22/06/2003 11:23:00 | Type : Comment |
|
| (another update: just remembered ODBC has CONCAT around. still doesn't solve it). In case this helps.... This is the original line without CONCAT: $sql = "SELECT TOP 10 SFilename, COUNT(*) as downloads from tbl06caller WHERE SFilename BETWEEN '20000' AND'29999' GROUP BY SFilename ORDER BY 2 desc;"; So the line would look like - $sql = "SELECT TOP 10 SFilename, COUNT(*) as downloads, CONCAT ('<img src="/logos/',SFilename,'.gif">') AS Image from tbl06caller WHERE SFilename BETWEEN '20000' AND'29999' GROUP BY SFilename ORDER BY 2 desc;"; But no matter what I try in the SQL it doesn't work. :( Any further help appreciated. |
|||
| By: sumotimor | Date: 22/06/2003 14:34:00 | Type : Comment |
|
| I'd avoid putting javascript in your database, it's messy and can be generated in PHP easily. Use these functions to show the src attribute for your images and sound embeds. <?php function urlForItemLogo($code) { return "/logos/$code.gif"; } function urlForItemSound($code) { return "/sounds/$code.wav"; } ?> <!-- display list of logos (I'm not sure about the exact odbc specifics) --> <?php $result = odbc_exec("SELECT * FROM LOGO"); while($row = odbc_fetch_array()) { echo "code: " . $row['code'] . " logo: <img src=\"" . urlForItemLogo($row['code']) . "\"> \n"; } ?> <!-- and you should be able to use the same kind of thing for your javascript --> |
|||
| By: wokadoo | Date: 22/06/2003 15:10:00 | Type : Comment |
|
| sumotimor, thanks for the tip.... My prob is I'm pulling my results with odbc_results_all and I'd prefer not to have to rewrite my code for odbc_fetch_array (which doesn't seem to work on my server anyway)... :( This is what the current code looks like: function x() { $sql = "SELECT TOP 10 SFilename, COUNT(*) as downloads from tbl06caller WHERE SFilename BETWEEN '20000' AND'29999' GROUP BY SFilename ORDER BY 2 desc;"; $conn = odbc_connect("database", "", "" ); if (!$conn) { print "Sorry, connection died.\n</html>"; exit; } if ($result = odbc_Exec($conn, $sql)) { odbc_result_all($result, "border = 0, class=whitetext"); } odbc_close($conn); } If we followed your idea then the odbc_result_all line would be replaced with if ($result = odbc_Exec($conn, $sql)) { while($row = odbc_fetch_query($result)) { echo "code: " . $row['code'] . " logo: <img src=\"" . urlForItemLogo($row['code']) . "\"> \n"; } And it doesn't work with odbc_result_all... Which is why I originally asked about JavaScript in the DB.... Any ideas? |
|||
| By: VGR | Date: 22/06/2003 15:33:00 | Type : Comment |
|
| @wokadoo : Please don't mess with the big boys if that's all you have to say. CONCAT() exists in SQL-Server, in ORACLE... Or else I wouldn't have mentioned it see for instance <A HREF="http://www.experts-exchange.com/Databases/Oracle/Q_20408676.html">http://www.experts-exchange.com/Databases/Oracle/Q_20408676.html</a> 2) ODBC has NOTHING to do with an SQL dialect. It's just a silly and unefficient interface towards supposedly-serious databases from not-so-serious OSes on absurd platforms (PCs) |
|||
| By: VGR | Date: 22/06/2003 15:36:00 | Type : Comment |
|
| when you say "line doesn't work" : perhaps we could know which error message you do get ? 2) if you're stuck with "Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\....\includes\inc.functions.php on line 220" : it has NOTHING to DO with CONCAT(). It's a PHP ERROR. Coul we see some lines (20 lines before, 2 after line 220) in file inc.functions.php ? |
|||
| By: wokadoo | Date: 22/06/2003 15:49:00 | Type : Comment |
|
| VGR, I do appreciate your help, but I'm trying to pursue all possible leads and I'm forced to work with what I'm given. Apologies if I sound like I'm questioning the wisdom of your answers (I'm not). This is the whole function - line 220 is the $sql encapsulation. ===================== function x() { $sql = "SELECT TOP 10 SFilename, COUNT(*) as downloads, CONCAT('<img src="/logos/',SFilename,'.gif">') AS image from tbl06caller WHERE SFilename BETWEEN '20000' AND'29999' GROUP BY SFilename ORDER BY 2 desc;"; $conn = odbc_connect("DB", "", "" ); if (!$conn) { print "Connection died.\n</html>"; exit; } if ($result = odbc_Exec($conn, $sql)) { odbc_result_all($result, "border = 0, class=whitetext"); } odbc_close($conn); } =============================== ... And before line 220 there's another function which is quite simple - function getPictures() { $sql = "SELECT * from Pictures ORDER BY Indexes;"; $conn = odbc_connect("DB", "", "" ); $nopages = odbc_num_rows($result); $totalp = $nopages / 30; while ($counter < $totalp) { print "$counter" . $totalp; $counter=$counter+1; } if (!$conn) { print "Connection died.\n</html>"; exit; } if ($result = odbc_Exec($conn, $sql)) { print "Query returned : " . odbc_num_rows($result) . "rows"; odbc_result_all($result, "border = 0, class=whitetext"); } odbc_close($conn); } ================================ Let me know if you need any more info. |
|||
| By: VGR | Date: 22/06/2003 15:54:00 | Type : Comment |
|
| of course it's wrong. You have put unescaped double quotes inside a double-quote-delimited string :D |
|||
| By: wokadoo | Date: 22/06/2003 15:59:00 | Type : Comment |
|
| OK, escaped. ;-) However... Warning: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]'CONCAT' is not a recognized function name., SQL state 37000 in SQLExecDirect in C:\Program Files\Apache Group\Apache2\htdocs\includes\inc.functions.php on line 220 And now line 220 is $sql = "SELECT TOP 10 SFilename, COUNT(*) as downloads, CONCAT('<img src=\"/logos/',SFilename,'.gif\">') AS image from tbl06caller WHERE SFilename BETWEEN '20000' AND'29999' GROUP BY SFilename ORDER BY 2 desc;"; ? |
|||
| By: VGR | Date: 22/06/2003 16:42:00 | Type : Comment |
|
| well, either your version of SQL-Server doesn't support CONCAT() - would be surprising - or your ODBC driver is parsing the query in stead of passing it to the native DB layer - I'm inclined to think this is the reason - thanks merdu$oft :/ I suggest you modify the function x() to concatenate yourself stuff to the SFileName value retrived via : $somevariable='<img src="/logos/{$SFilename}.gif">'; function x() { $sql = "SELECT TOP 10 SFilename, COUNT(*) as downloads, SFilename from tbl06caller WHERE SFilename BETWEEN '20000' AND'29999' GROUP BY SFilename ORDER BY 2 desc;"; |
|||
| By: wokadoo | Date: 23/06/2003 05:09:00 | Type : Comment |
|
| Sorry VGR, could you be a bit clearer on what I need to do to function x()? I have created the $somevariable line... But I try to incorporate it into the function and it doesn't seem to work. Could you explain? Thanks. |
|||
| By: VGR | Date: 23/06/2003 05:21:00 | Type : Comment |
|
| It's difficult for me, because I never use your style of programming, especially odbc_result_all () which I don't understand, especially the litteral string parameter... with a odbc_fetch_array(), things would be clearer. Anyway, **if*** result_all returns you an array of pair values, then do : $result['SFilename']='<img src="/logos/{$result['SFilename']}.gif">'; |
|||
| By: wokadoo | Date: 23/06/2003 05:38:00 | Type : Comment |
|
| VGR - I appreciate your efforts. Sometimes I wish I just had MySQL to work with....! I tried your suggestion and now, the following lines: if ($result = odbc_Exec($conn, $sql)) { odbc_result_all($result, "border = 0, class=whitetext"); $result['SFilename']="<img src=\"/logos/{$result['SFilename']}.gif\">"; } Warning: Cannot use a scalar value as an array in C:\Program Files\Apache Group\Apache2\htdocs\includes\inc.functions.php on line 233 Line 233 is $result['SFilename']="<img src=\"/logos/{$result['SFilename']}.gif\">"; Don't suppose you can get somewhere with that? (unless you'd like to try re-writing my results with odbc_fetch_array, of course...!) |
|||
| By: VGR | Date: 23/06/2003 05:51:00 | Type : Comment |
|
| yes, sorry. $result is apparently the "resource ID", not the returned array WHERE ARE the results from the odbc_result_all() cvall ?!? How do you reference them afterwards ? |
|||
| By: wokadoo | Date: 23/06/2003 18:02:00 | Type : Comment |
|
| Not entirely sure what you mean, but... Once the results are presented, they are presented in a different PHP page with the command <?php x() ?> The results are simply presented - they are not otherwise accessible in any way (that is, like read only). That's what I'm trying to get past. |
|||
| By: VGR | Date: 23/06/2003 19:16:00 | Type : Comment |
|
| oh yes !?! So they are in fact PRINTED OUT by odbc_result_all() ? not put into an array variable ? Well, then : please use a "$result = odbc_Exec($conn, $sql) or die("bad query ".mysql_error()); while ($res=odbc_fetch_array($result)) {...}" and everything will be fine |
|||
| By: wokadoo | Date: 23/06/2003 19:19:00 | Type : Comment |
|
| Sorry VGR, but can you write the entire code out for me? I'm now getting an 'undefined_function: odbc_fetch_array()" (and my brain is dying from staring too much at the computer)..... |
|||
| By: wokadoo | Date: 23/06/2003 19:20:00 | Type : Comment |
|
| The code is: if ($result = odbc_Exec($conn, $sql)) { while ($res=odbc_fetch_array($result)) odbc_result_all($result, "border = 0, class=whitetext"); $result['SFilename']="<img src=\"/logos/{$result['SFilename']}.gif\">"; } |
|||
| By: VGR | Date: 23/06/2003 19:29:00 | Type : Comment |
|
| sorry, I never use ODBC, I hate ODBC, je conchie ODBC, I despise ODBC... :D ODBC is crap. Reading the PHP documentation for "unified ODBC functions", I read this that will save you : garrieDOTpowersATkclDOTacDOTuk 21-Oct-2002 07:45 This function will return all of the rows returned by a query in an array. $resultSet['fieldNames'] contains an array of fieldnames keyed by field number $resultSet[n], where n is the record number, contains an associative array keyed on fieldname. - Garrie ---------------------------------------- function odbc_fetch_resultset($resID) { /* Return all the rows returned by a query in an array. */ $resultSet=array(); // Assign the field names to $resultSet['fieldNames'] $fCount = odbc_num_fields($resID); for ($i=1; $i<= $fCount; $i++){ $fNames[$i] = odbc_field_name($resID, $i); } $resultSet['fieldNames']=$fNames; // Assign the records for ($i=1; odbc_fetch_row($resID,$i); $i++){ $record=array(); for ($j = 1; $j <= $fCount; $j++){ $fName = odbc_field_name($resID, $j); $record[$fName]=odbc_result($resID, $j); } $resultSet[$i]=$record; } return ($resultSet); } so just copy-paste the function above in an include 'or the main script if it's the only one using ODBC access to the DB ;-)) and then do : if ($result = odbc_Exec($conn, $sql)) { $res=odbc_fetch_resultset($result); // don't know what to do with this : "border = 0, class=whitetext"); for ($i=0;$i<count($res);$i++) $res[$i]['SFilename']="<img src=\"/logos/{$res[$i]['SFilename']}.gif\">"; } // on output, you've to check count($res) to see whether it's >0 and if yes, then $res contains the results. You can print them, modify them again, etc |
|||
| By: wokadoo | Date: 23/06/2003 19:46:00 | Type : Comment |
|
| Argh.... I think we're getting closer... So close yet so far. Now getting infinite loops :( |
|||
| By: VGR | Date: 23/06/2003 19:53:00 | Type : Comment |
|
| ok, try this then : if ($result = odbc_Exec($conn, $sql)) { $res=odbc_fetch_resultset($result); // don't know what to do with this : "border = 0, class=whitetext"); echo '<pre>'; print_r($res); echo '</pre>'; } |
|||
| By: wokadoo | Date: 23/06/2003 19:56:00 | Type : Comment |
|
| Crap... I get the actual dump - Array ( [fieldNames] => Array ( [1] => SFilename [2] => Downloads ) [1] => Array ( [SFilename] => 20549 [Downloads] => 237 ) [2] => Array ( [SFilename] => 20116 [Downloads] => 193 ) [3] => Array ( [SFilename] => 20145 [Downloads] => 137 ) [4] => Array ( [SFilename] => 20912 [Downloads] => 91 ) [5] => Array ( [SFilename] => 20290 [Downloads] => 81 ) [6] => Array ( [SFilename] => 20676 [Downloads] => 81 ) [7] => Array ( [SFilename] => 20527 [Downloads] => 79 ) [8] => Array ( [SFilename] => 20567 [Downloads] => 75 ) [9] => Array ( [SFilename] => 20345 [Downloads] => 65 ) [10] => Array ( [SFilename] => 20312 [Downloads] => 64 ) ) |
|||
| By: VGR | Date: 23/06/2003 20:11:00 | Type : Comment |
|
| ok, it seems good. Change my line : for ($i=1;$i<=count($res);$i++) $res[$i]['SFilename']="<img src=\"/logos/{$res[$i]['SFilename']}.gif\">"; and leave the print_r() call to check whether the SFileName elements have been modified correctly. |
|||
| By: wokadoo | Date: 23/06/2003 20:19:00 | Type : Comment |
|
| Nope, back to infinite looping again, so can't tell. function x() { $sql = "SELECT TOP 10 SFilename, COUNT(*) as Downloads from tbl06caller WHERE SFilename BETWEEN '20000' AND '29999' GROUP BY SFilename ORDER BY 2 desc;"; $conn = odbc_connect("DB", "", "" ); if (!$conn) { print "Died!</html>"; exit; } if ($result = odbc_Exec($conn, $sql)) { $res=odbc_fetch_resultset($result); echo '<pre>'; print_r($res); echo '</pre>'; for ($i=1;$i<=count($res);$i++) $res[$i]['SFilename']="<img src=\"/logos/{$res[$i]['SFilename']}.gif\">"; } odbc_close($conn); } ?> |
|||
| By: VGR | Date: 23/06/2003 20:25:00 | Type : Comment |
|
| ok, then "les grands moyens" :D $res=odbc_fetch_resultset($result); echo '<pre>'; print_r($res); echo '</pre>'; echo '<hr>'.count($res).' results '; exit; // delete this after the first test i=1; echo "res[$i]['SFilename']= {$res[$i]['SFilename']} "; exit; // dor second test |
|||
| By: wokadoo | Date: 23/06/2003 20:29:00 | Type : Comment |
|
| 1st test - Array ( [fieldNames] => Array ( [1] => SFilename [2] => Downloads ) [1] => Array ( [SFilename] => 20549 [Downloads] => 241 ) [2] => Array ( [SFilename] => 20116 [Downloads] => 193 ) [3] => Array ( [SFilename] => 20145 [Downloads] => 137 ) [4] => Array ( [SFilename] => 20912 [Downloads] => 91 ) [5] => Array ( [SFilename] => 20290 [Downloads] => 81 ) [6] => Array ( [SFilename] => 20676 [Downloads] => 81 ) [7] => Array ( [SFilename] => 20527 [Downloads] => 80 ) [8] => Array ( [SFilename] => 20567 [Downloads] => 75 ) [9] => Array ( [SFilename] => 20345 [Downloads] => 65 ) [10] => Array ( [SFilename] => 20312 [Downloads] => 65 ) ) -------------------------------------------------------------------------------- 11 results 2nd test - Array ( [fieldNames] => Array ( [1] => SFilename [2] => Downloads ) [1] => Array ( [SFilename] => 20549 [Downloads] => 241 ) [2] => Array ( [SFilename] => 20116 [Downloads] => 193 ) [3] => Array ( [SFilename] => 20145 [Downloads] => 137 ) [4] => Array ( [SFilename] => 20912 [Downloads] => 91 ) [5] => Array ( [SFilename] => 20290 [Downloads] => 81 ) [6] => Array ( [SFilename] => 20676 [Downloads] => 81 ) [7] => Array ( [SFilename] => 20527 [Downloads] => 80 ) [8] => Array ( [SFilename] => 20567 [Downloads] => 75 ) [9] => Array ( [SFilename] => 20345 [Downloads] => 65 ) [10] => Array ( [SFilename] => 20312 [Downloads] => 65 ) ) -------------------------------------------------------------------------------- 11 results res[1]['SFilename']= 20549 |
|||
| By: VGR | Date: 23/06/2003 20:41:00 | Type : Comment |
|
| stupid me and silly function ok : function x() { $sql = "SELECT TOP 10 SFilename, COUNT(*) as Downloads from tbl06caller WHERE SFilename BETWEEN '20000' AND '29999' GROUP BY SFilename ORDER BY 2 desc;"; $conn = odbc_connect("DB", "", "" ); if (!$conn) { print "Died!</html>"; exit; } if ($result = odbc_Exec($conn, $sql)) { $res=odbc_fetch_resultset($result); $nbresults=count($res)-1; // column names are returned in row zero for ($i=1;$i<=$nbresults;$i++) $res[$i]['SFilename']="<img src=\"/logos/{$res[$i]['SFilename']}.gif\">"; } odbc_close($conn); //test echo '<hr>Verification : '; echo "$nbresults results found "; echo '<pre>'; print_r($res); echo '</pre>'; //EoTest } ?> Nota bene : you'll have to rely/transmit out of x (via GLOBAL keyword) the value of $nbesults in stead of count($res) ; else you'll have to always remember that count($res)=11 => results are numbered in indices 1 to 10 |
|||
| By: wokadoo | Date: 23/06/2003 20:53:00 | Type : Comment |
|
| Yay! Images are now being outputted (albeit with 5 %20 between SFilename no. and .gif)... Now to get rid of the ugly array structures and just show <SFilename no.> <GIF> You've more than earnt the points as far as I'm concerned... Wish I could give you more! ;-) |
|||
| By: VGR | Date: 23/06/2003 21:06:00 | Type : Comment |
|
| Yes, that's because you used VARCHAR(x) and ODBC is crap : it is padding them to the right with spaces ! huh huh huh what a sh*t ! ok, use trim() to get rid of the spaces : for ($i=1;$i<=$nbresults;$i++) $res[$i]['SFilename']='<img src="/logos/".trim($res[$i]['SFilename']).'.gif">'; it should be fine. And no, you can't "get rid of the array structure" : you don't like it ? :D ok, to get rid of it : function x() { GLOBAL $nbresults, $results; $results=array(); // empty $sql = "SELECT TOP 10 SFilename, COUNT(*) as Downloads from tbl06caller WHERE SFilename BETWEEN '20000' AND '29999' GROUP BY SFilename ORDER BY 2 desc;"; $conn = odbc_connect("DB", "", "" ); if (!$conn) { print "Died!</html>"; exit; } if ($result = odbc_Exec($conn, $sql)) { $res=odbc_fetch_resultset($result); $nbresults=count($res)-1; // column names are returned in row zero for ($i=1;$i<=$nbresults;$i++) $results[]='<img src="/logos/".trim($res[$i]['SFilename']).'.gif">'; } // if results returned odbc_close($conn); return($results); } beware, now $results is an array[0..$nbresults-1] (as usual) containing only the (modified) image links |
|||
| By: VGR | Date: 23/06/2003 21:08:00 | Type : Comment |
|
| sorry, I see a quoting problem here : for ($i=1;$i<=$nbresults;$i++) $results[]='<img src="/logos/'.trim($res[$i]['SFilename']).'.gif">'; |
|||
| By: wokadoo | Date: 23/06/2003 21:17:00 | Type : Comment |
|
| Hmmm... Empty results... :( |
|||
| By: wokadoo | Date: 23/06/2003 21:18:00 | Type : Comment |
|
| $nbresults returns 10, so that's fine... but $results is empty. |
|||
| By: VGR | Date: 23/06/2003 21:25:00 | Type : Comment |
|
| strange. Show me your x() code as it is now |
|||
| By: wokadoo | Date: 23/06/2003 21:30:00 | Type : Comment |
|
| function x3() { GLOBAL $nbresults, $results; $results=array(); // empty $sql = "SELECT TOP 10 SFilename, COUNT(*) as Downloads from tbl06caller WHERE SFilename BETWEEN '20000' AND '29999' GROUP BY SFilename ORDER BY 2 desc;"; $conn = odbc_connect("DB", "", "" ); if (!$conn) { print "Died!</html>"; exit; } if ($result = odbc_Exec($conn, $sql)) { $res=odbc_fetch_resultset($result); $nbresults=count($res)-1; // column names are returned in row zero for ($i=1;$i<=$nbresults;$i++) $results[]='<img src=\"/logos/'.trim($res[$i]['SFilename']).'.gif\">'; } odbc_close($conn); return($results); echo $results; //test // echo '<hr>Verification : '; // echo "$nbresults results found "; // echo '<pre>'; // print_r($res); // echo '</pre>'; //EoTest } ?> |
|||
| By: VGR | Date: 23/06/2003 21:40:00 | Type : Comment |
|
| no no no for ($i=1;$i<=$nbresults;$i++) $results[]='<img src=\"/logos/'.trim($res[$i]['SFilename']).'.gif\">'; // QUOTE PROBLEM HERE // should be : for ($i=1;$i<=$nbresults;$i++) $results[]='<img src="/logos/'.trim($res[$i]['SFilename']).'.gif\">'; } odbc_close($conn); return($results); echo $results; // you can't put any code after a return() statement : do it BEFORE or do it OUTSIDE the function, ie after the call to x3() |
|||
| By: VGR | Date: 23/06/2003 21:40:00 | Type : Comment |
|
| and you can't either ECHO an array ! use the pre/print_r block if you wanna output the array |
|||
| By: VGR | Date: 23/06/2003 21:41:00 | Type : Comment |
|
| perhaps you wanted the images as a long string, but you never said under which form : -just images following each other ? (awful) -in a table structure ? -separated by ??? |
|||
| By: wokadoo | Date: 23/06/2003 21:43:00 | Type : Comment |
|
| Ahhh... (forgive me, has been a loooong day) Table structure (see original question), so... 21111 <21111.gif> 21112 <21112.gif> 21113 <21113.gif> 21114 <21114.gif> etc. etc. Would that affect anything? |
|||
| By: VGR | Date: 23/06/2003 22:01:00 | Type : Answer |
|
| ok if ($result = odbc_Exec($conn, $sql)) { $res=odbc_fetch_resultset($result); $nbresults=count($res)-1; // column names are returned in row zero for ($i=1;$i<=$nbresults;$i++) { $results[$i-1]['code']=trim($res[$i]['SFilename']); $results[$i-1]['image']='<img src="/logos/".trim($res[$i]['SFilename']).'.gif">'; } // for } // if results returned odbc_close($conn); return($results); } after the call to x3(), to display the results, just do : echo '<table>'; for ($i=0;$i<count($results);$i++) { // classical way, and $nbresults can be discarded echo "<tr><td>{$results[$i]['code']}</td><td>{$results[$i]['image']}</td></tr>"; } // for (useless but cleaner) echo '</table>'; |
|||
| By: wokadoo | Date: 23/06/2003 22:13:00 | Type : Comment |
|
| It's working! It's working! .... well, nearly. And I'm sure this is the last hurdle. This line: $results[$i-1]['image']="<img src=\"/logos/\".trim($res[$i]['SFilename']).\".gif\">"; isn't pulling the GIF file. There is only a broken image and if you click on the image's properties in IE the filename doesn't show up. Which in other words means the line isn't parsing properly :/ Any idea? I'm sure it's something to do with all the double quotes/single quotes/escaping..! |
|||
| By: wokadoo | Date: 23/06/2003 22:14:00 | Type : Comment |
|
| Don't worry, it was the quotes! The correct line is $results[$i-1]['image']='<img src="/logos/'.trim($res[$i]['SFilename']).'.gif">'; Phew! I can now go home and sleep. :) Many, many thanks again VGR. You have saved my life. :P Have a good week. |
|||
| By: VGR | Date: 23/06/2003 22:43:00 | Type : Comment |
|
| ouf 8-) |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








