Jump to content

Add img item to existing forum table to be displayed by CSS table code once retrived from the forum table in the SQl db


Html
 Share

Recommended Posts

Hello,

I would like to add an img_item to this table, so when the table is retrieved and displayed on a page, a default image would be posted next to this column.

So this is the current layout, I tried editing to see what happens, the CSS just creates another column, but it moves the rest of the data along once loaded, so only two are working, the image appear before Posted By.

 ;

# Open database connection.
require ( 'connect_db.php' ) ;

# Display body section, retrieving from 'forum' database table.
$q = "SELECT * FROM forum" ;
$r = mysqli_query( $dbc, $q ) ;
if ( mysqli_num_rows( $r ) > 0 )
{
  echo '<div><table><tr><th>Posted By</th><th id="msg">Message</th></tr></div>';
  while ( $row = mysqli_fetch_array( $r, MYSQLI_ASSOC ))
  {
    echo '<tr><td>' . $row['first_name'] .' '. $row['last_name'] . '<br>'. $row['post_date'].'</td>
    <td>' . $row['message'] . '</td> </tr>';
  }
  echo '</table>' ;
}
else { echo '<p>There are currently no messages.</p>' ; }

# Close database connection.
mysqli_close( $dbc ) ;
?>

So item_img would go $row

'<div><table><tr><th>Img</th>

Below is item 7 in the forum table

item_img

 

 

 

varchar(20)

 

 

 

latin1_swedish_ci

 

 

 

 

No

 

 

 

None

Link to comment
Share on other sites

I don't see additional columns and didn't see any css in your post.

I stripped out the php and added borders and got what i expected:

EDIT:

What does a row or two of your results actually look like?

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
  border: 1px solid black;
}

table {
  width: 100%;
}
</style>
<head>
<body>

<div><table ><tr><th>Posted By</th><th id="msg">Message</th></tr></div>
  
 
<tr><td>$row['first_name'] $row['last_name']<br>$row['post_date']</td>
    <td>$row['message'</td> </tr>
<tr><td>$row['first_name'] $row['last_name']<br>$row['post_date']</td>
    <td>$row['message'</td> </tr>
<tr><td>$row['first_name'] $row['last_name']<br>$row['post_date']</td>
    <td>$row['message'</td> </tr>
<tr><td>$row['first_name'] $row['last_name']<br>$row['post_date']</td>
    <td>$row['message'</td> </tr>	
  </table>
</body>
</html>

 

Edited by niche
Link to comment
Share on other sites

The CSS is in the header2.html

<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><?php echo $page_title; ?></title>
<link rel="stylesheet" href="includes/style2.css">
</head>
<style>
img {
  display: block;
  margin-left: 10;
  margin-right: 70;
  width: 15%;
}
.center {
  margin: auto;
  width: 60%;
  border: 3px solid #73AD21;
  padding: 10px;
} 
</style>
<body>
<header><h1></h1></header>
header > h1 { border-bottom: 1px dashed black ; font-style: italic ; font-size: x-large; }
footer > p { border-top: 1px dashed black ; font-style: italic ; }
table { border-spacing:5px; width:530px; position: right; }
th { color:#FFF; background:#000; text-align:left; }
td { border-bottom:1px solid black; background:#F0F0F0; padding:3px; text-align:left; vertical-align:top;}
p#err_msg { color:#F00; font-weight:bold; }

Here it is style2.css

 

Link to comment
Share on other sites

There's a position: right; Now! is there? must be short-code property for position: absolute;  on right? maybe? have to look it up! just can't keep up with all these new properties they come out with.

Edited by dsonesuk
Link to comment
Share on other sites

Posted (edited)

All of this is from In Easy step's code, Php & Mysql book, the code isn't available to download via the site without an account. Since I backed it up last year after I closed the free hosting with infinityfree.net, thought I'd try it once more.

I was simply wanted to add a default avatar so when any user posts, an image will load next to it. So I need css to include it, and the image needs to be stored in the table forum, to print it once the message has been sent to the forum table, and the code above displays it.

My post isn't viewable if I log out.🤨

Edited by Html
My post isn't viewable
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...