-1

I will preface this with I am not knowledgeable and am using mysql not mysqli , I plan to change, this is only being used in my home for family. I have a database using phpmyadmin. I would like pull out the value to a webpage and have the result represented by specific image. I am currently just getting a blank icon as a result because it is not actually pulling the info, here is code, I know I have my tags incorrect is likely the issue

<?php

$db="homebase";
$link = mysql_connect("localhost", "sql","sql");
if (! $link)
die("ACCESS DENIED");
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());

$sql = "SELECT * FROM table";

$rs_result = mysql_query ($sql);
$num_rows = mysql_num_rows($rs_result);
$query = mysql_query("SELECT * FROM table"); 
$number=mysql_num_rows($query); 

print "<table width=250 Align=Left border=1  bordercolor=\"#000000\" bgcolor=\"E6E6E6\"  style=\"border-collapse: collapse\" cellpadding=\"2\" cellspacing=\"1\"> 
 <tr>
<td background=\"backgrounds/blue.jpg\"><font color=\"white\"><b>Availability</b></font></td>

\n";
while($rows=mysql_fetch_array($rs_result))
    
?>  

<tr bgcolor='#e6e6e6'>
<td>
<img src="backgrounds/<?= $rows['Away'] ?>.png" border="0" align="center">
</td>
</tr>
</tr>
</table>

When I look in Chrome elements I can see this

img src="backgrounds/.png" border="0" align="center"

so value is not being pulled from db. Thank you

ok so I worked backwards and I am now getting the value but I want to convert the value to an image, I am only using the 1 set of php

<?php

$db="homebase";
$link = mysql_connect("localhost", "sql","sql");
if (! $link)
die("ACCESS DENIED");
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());

$sql = "SELECT * FROM call";

$rs_result = mysql_query ($sql);
$num_rows = mysql_num_rows($rs_result);
$query = mysql_query("SELECT * FROM call"); 
$number=mysql_num_rows($query); 

print "<table width=250 Align=Left border=1  bordercolor=\"#000000\" bgcolor=\"E6E6E6\"  style=\"border-collapse: collapse\" cellpadding=\"2\" cellspacing=\"1\"> 
 <tr>
<td background=\"backgrounds/blue.jpg\"><font color=\"white\"><b>Availability</b></font></td>


\n";
while($rows=mysql_fetch_array($rs_result)){
print "<tr>\n";
echo "<tr bgcolor='#e6e6e6'>
<td>".$rows['Away']."</td>
</tr>";
print "</tr>\n";
}
print "</table>\n";
mysql_close($link);

?>
  • What have you tried to debug the problem? Where are you stuck? – Nico Haase Apr 15 '21 at 12:05
  • Also, using `mysql_*` is not only deprecated since years, but has been removed in PHP 7.0 which is already some years old.... – Nico Haase Apr 15 '21 at 12:06
  • Take a look at your PHP error log for any errors, warnings or notices. Alternatively, you could [display PHP errors](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display). Check the simplest symptoms first - is there really a column in your database called `Away`? Is it capitalized (array indices are case-sensitive)? – El_Vanja Apr 15 '21 at 12:07
  • Is your table really called `table`? If yes, then you need to put it in back ticks since it's a reserved word in MySQL (and is a very non-descript and ambiguous name) – M. Eriksson Apr 15 '21 at 12:15
  • `font` tag also was deprecated like 12 years ago, find a better tutorial – Lawrence Cherone Apr 15 '21 at 12:21
  • 1
    When posting a question like this, you need to post the schema for the tables you're using together with some example data. It's hard to know what you're doing wrong if we don't know what it should look like. You should also always check your web servers error log to see if there are any errors in there that might be a clue. – M. Eriksson Apr 15 '21 at 12:24
  • Thanks all, no the table is actually called call, database is homebase. There is only ever 1 row in the table, updates overwrite the values of that one column..update where id=1 type of thing. Columns are Name, Cellphone, StartDate, EndDate, Away and id . So do the php tags look like they are in the correct spots? – john bryden Apr 15 '21 at 12:40
  • What have you tried to debug the problem? If you dumped `$rows`, what does it contain? – Nico Haase Apr 15 '21 at 12:48
  • "I want to convert the value to an image" - what does that mean? As nobody, except you, knows what that value contains, it's pretty hard to tell you how to convert that to an image – Nico Haase Apr 15 '21 at 13:30
  • figured it out on my own , yay me – john bryden Apr 15 '21 at 13:55

1 Answers1

0
<td><img src=\"backgrounds/$rows[Away].png\"</td>

I'm dumb but it works, thanks for the input