have two users side by side in a members page - php

so I would like in my registered users page, or members page all my users on it (that's the easy part) where i'm having trouble is I would like to have 2 users side by side, and then on the next line 2 other users and so on.
Something like this:
enter image description here
i'm using php and it's to use after a php query from mysql, this is my code at the moment:
<?php
include '_database/database.php';
session_start();
$current_user = $_SESSION['user_username'];
$sql = "SELECT * FROM users order by user_id desc";
$result = mysqli_query($database,$sql) or die(mysqli_error($database));
while($rws = mysqli_fetch_array($result)){
?>
<table style="width: 200px;">
<tbody>
<tr>
<td style="width: 100px;"><img src="userfiles/avatars/<?php echo $rws['user_avatar'];?>" width="100" height="100"></td>
<td style="width: 200px;">
<?php echo $rws['user_country'];?> <?php echo $rws['user_username'];?><br>
<?php echo $rws['user_joindate'];?><br>
1<br>
2<br>
3<br>
See more
</td>
</tr>
</tbody>
</table>
<?php } ?>
Thank you !

<?php
include '_database/database.php';
session_start();
$current_user = $_SESSION['user_username'];
$sql = "SELECT * FROM users order by user_id desc";
$result = mysqli_query($database,$sql) or die(mysqli_error($database));
?>
<div class="container" style="width: 200px;">
<?php while($rw = mysqli_fetch_array($result)){ ?>
<div class="user" style="width: 100px; float: left;">
<img src="userfiles/avatars/<?php echo $rw['user_avatar'];?>" width="100" height="100">
<div class="userInfo">
<?php echo $rw['user_country'] . ' ' . $rw['user_username'];?><br>
<?php echo $rw['user_joindate'];?><br>
<!--Content--><br>
<!--Content--><br>
<!--Content--><br>
See more
</div>
</div>
<?php } ?>
</div>
i haven't tested the code.
You also can use for design HTML, CSS and JS frameworks like Bootstrap

Related

Dynamic Accordion Repetitive Code

I have built a navigation page in an accordion format using mysqli and php. You can see an example at
[1]: http://www.outerhebridesalgae.uk/marine/marine-taxononic-list.php/ "Marine Algae".
This works perfectly well, but the coding is very repetitive as I am repeating the same code for each heading in the accordion. This is fine for a limited number of headings, but some of my tables have 30 or more headings! Is there a more efficient approach? Thank you for your assistance.
A sample of the code follows:
<?phprequire '../assets/includes/conn.inc.php';
$query1 = mysqli_query($connect, "SELECT * FROM marine WHERE famid='1' ORDER BY marine.species");
$row1 = mysqli_fetch_assoc($query1);
$totalRows_query1 = mysqli_num_rows($query1);
$query2 = mysqli_query($connect, "SELECT * FROM marine WHERE famid='2' ORDER BY marine.species");
$row2= mysqli_fetch_assoc($query2);
$totalRows_query2 = mysqli_num_rows($query2);
$query4 = mysqli_query($connect, "SELECT * FROM marine WHERE famid='4' ORDER BY marine.species");
$row4= mysqli_fetch_assoc($query4);
$totalRows_query4 = mysqli_num_rows($query4);
?>
<!DOCTYPE html>
<head>.......</head>
<body>
<div class="uk-panel uk-panel-box uk-margin">
<h2 class="uk-panel-title">Chlorophyta - Green Seaweeds</h2>
<div id="firstpane" class="msg_list">
<p class="msg_head"> <?php echo $row1['family']; ?><img src="../images/arrow.jpg" alt="arrow open" align="right"></p>
<div class="msg_body">
<table width="100%" >
<?php do { ?>
<tr>
<td id="marine.species"><?php echo $row1['species']; ?></td>
<?php } while ($row1 = mysqli_fetch_assoc($query1)); ?>
</tr>
</table>
</div>
<p class="msg_head"><?php echo $row2['family']; ?><img src="../images/arrow.jpg" alt="arrow open" align="right"></p>
<div class="msg_body">
<table width="100%" >
<?php do { ?>
<tr>
<td id="marine.species"><?php echo $row2['species']; ?></td>
<?php } while ($row2 = mysqli_fetch_assoc($query2)); ?>
</tr>
</table>
</div>
<p class="msg_head"><?php echo $row4['family']; ?><img src="../images/arrow.jpg" alt="arrow open" align="right"></p>
<div class="msg_body">
<table width="100%" >
<?php do { ?>
<tr>
<td id="marine.species"><?php echo $row4['species']; ?></td>
<?php } while ($row4 = mysqli_fetch_assoc($query4)); ?>
</tr>
</table>
</div></body></html>

PHP, CSS class issue

I've been dealing with this problem like 3 days.
I have a PHP code that echo es images from database. The class IMG is not responding, it should show margin-bottom: 60px but it is not. I've putted the class in img class-name src but still nothing.
Thank you
<table class="table-image">
<?php
$query = "SELECT * FROM images ORDER BY id DESC";
$result = mysqli_query($connect, $query);
while($row = mysqli_fetch_array($result))
{
echo '
<tr>
<td>
<img src="data:image/jpeg;base64,'.base64_encode($row['name'] ).'" height="480" width="550" class="img" " />
</td>
</tr>
';
}
?>
</table>
And CSS
.img{
width: 100%;
height: auto;
margin-bottom: 60px;
}
You have two quotes at the end.
class="img" " />
<table class="table-image">
<?php
$query = "SELECT * FROM images ORDER BY id DESC";
$result = mysqli_query($connect, $query);
while($row = mysqli_fetch_array($result)): ?>
<tr>
<td>
<img src="data:image/jpeg;base64,<?php echo base64_encode($row['name'] ); ?>" height="480" width="550" class="img" />
</td>
</tr>
<?php endwhile; ?>
</table>

Aligning image from php using table

Im trying to align the image that I fetched from my database with a text that is also fetched from database. The text seems ok but the image just stick to the left
<div align="center">
<p>
<?php
$vid =$_REQUEST[#id];
include 'conn.php';
$sql = mysql_query("SELECT * FROM product_car where Id = '$vid'");
$vid = 'Id';
$vnamaproduk = 'NamaProduk';
$vharga = 'Harga';
$vpenerangan = 'Penerangan';
$vgambar = 'Gambar';
?>
<table width="1000" border="0" align="center">
<?php
while($row= mysql_fetch_assoc($sql)){
?>
<tr>
<td>
<img src="gambar/car/<?php echo $row[$vgambar];?>"width="500" height="400"/>
</td>
<td>
<?php
echo "<br>Product Id : ".$row[$vid];
echo "<br>Product Name : ".$row[$vnamaproduk];
$harganew =sprintf('%0.2f',$row[$vharga]);
echo "<br>Price : RM".$harganew;
echo "<br> <br>".$row[$vpenerangan];
echo "<br>";
}
?>
ADD TO CART
</td>
</tr>
</table>
</div>
is the image displayed as a block?
img {
display:block;
margin:auto;
}
If you want to center the image, you could try this
img {
margin: auto 0;
}

Foreach loop are displaying same rows multiple times

I have a problem with my first attempt at making a foreach loop.
My problem is, that I'm only trying to call out two rows to be displayed, which kinda works, although they are being displayed as many times as there are different rows in my table.
My code looks like this:
$sql = "SELECT * FROM webpages";
$result = mysql_query($sql);
$assoc_query = mysql_fetch_assoc($result);
<?php foreach ($assoc_query as $value) { ?>
<tr>
<td>
<div id='pageimg'><img src= <?php echo $assoc_query['pic'];?> ></div>
</td>
<td>
<div id="pagename"><?php echo $assoc_query['name']; ?> </div>
</td>
</tr>
<?php } ?>
It's being displayed like so on the page:
/picture/ DAK
/picture/ DAK
/picture/ DAK
/picture/ DAK
Hope you can help me:)
<?php
$sql = "SELECT * FROM webpages";
$result = mysql_query($sql);
$counter=0;
while($row= mysql_fetch_assoc($result))
{
$assoc_query[$counter] = $row;
$counter++;
}
foreach ($assoc_query as $value) { ?>
<tr>
<td>
<div id='pageimg'><img src= <?php echo $value['pic'];?> ></div>
</td>
<td>
<div id="pagename"><?php echo $value['name']; ?> </div>
</td>
</tr>
<?php } ?>
Instead of foreach you will want a while. What you are doing here is looping the elements of array $assoc_query.
A while loop will get the next result set to be used.
while($assoc_query = mysql_fetch_assoc($result)){
//Do your thing
}
Also please consider updating from mysql_ to mysqli_ or PDO. What you are using is depreciated and there is added security with the newer ones.
this can't be done with foreach loop unless you gonna show 1 user's information only using limit Clause or Where Clause otherwise that it's useless
instead you need a while loop like this
<?php while ($assoc_query = mysql_fetch_assoc($result)) { ?>
<tr>
<td>
<div id='pageimg'><img src= <?php echo $assoc_query['pic'];?> ></div>
</td>
<td>
<div id="pagename"><?php echo $assoc_query['name']; ?> </div>
</td>
</tr>
<?php } ?>
You should do it like this:
$sql = "SELECT * FROM webpages";
$result = mysql_query($sql);
while ($assoc_query = mysql_fetch_assoc($result)) {
?>
<tr>
<td>
<div id='pageimg'><img src= <?php echo $assoc_query['pic'];?> ></div>
</td>
<td>
<div id="pagename"><?php echo $assoc_query['name']; ?> </div>
</td>
</tr>
<?php } ?>
That should work. But as said before you shouldn't code like this. Use mysqli or PDO like nerdlyist says.
#Nerdlyist
$sql = "SELECT * FROM webpages";
$result = mysql_query($sql);
$assoc_query = mysql_fetch_assoc($result);
<?php while ($assoc_query = mysql_fetch_assoc($result)) {
?>
<tr>
<td>
<div id='pageimg'><img src= <?php echo $assoc_query['pic'];?> ></div>
</td>
<td>
<div id="pagename"><?php echo $assoc_query['name']; ?> </div>
</td>
</tr>
<?php } ?>

Multi checkbox post proplem

I wanna check same exist database, but doesn't work the $check. What's wrong ı cannot find.
ı taking this error when post;
error 1-Members not added :(
Mysql error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''459' at line 1
error 2- 459 memb_id already in databese, try again!
This is my code:
<?php
$row_data = array();
foreach($_POST['checkbox'] as $row=>$Name) {
$name=mysql_real_escape_string($Name);
$memb_id=mysql_real_escape_string($_POST['memb_id'][$row]);
$memb_srnm=mysql_real_escape_string($_POST['memb_srnm'][$row]);
$kur_id=mysql_real_escape_string($_POST['kur_id'][$row]);
$row_data = array("'$memb_id'", "'$memb_srnm'", "'$kur_id'");
}
if (!empty($row_data)) {
$check = mysql_query("SELECT * FROM basvurular WHERE memb_id='$memb_id");
if (mysql_affected_rows() ){
echo '<h4 class="alert_error"><strong>'.ss($memb_id).'</strong> already in databese, try again! </h4>';
header('Location: index.php');
} else {
$query = 'INSERT INTO basvurular (memb_id, memb_srnm, basvur_kurid) VALUES (' .implode(',', $row_data) . ')';
}
if (mysql_query($query)){
echo '<h4 class="alert_success"> <label style="color: blue; font-size: 26px; font-weight: bold;"><img style="width: 4%" src="images/pers2.png" alt=""/>-'.mysql_affected_rows().'- </label> Succesfull :) </h4>';
header('Location: index.php');
}else{
echo '<h4 class="alert_error">Members not added :( <br> Mysql Error:'.mysql_error().'</h4>';
return false;}
}
?>
<article class="module width_3_quarter" style="padding-bottom: 10px; width: 95%">
<header>
<div style="float:right;font-size:14px;font-weight: bold; padding:10px"></div>
<h3 class="tabs_involved">POST SELECTED</h3>
</header>
<div class="tab_container">
<?php
$query = query("SELECT * FROM members INNER JOIN kurumlar ON kurumlar.kur_id = members.kur_id WHERE kurumlar.kur_id=' ".$_SESSION["kur_id"]." ' && ceza=0 ORDER BY memb_id DESC");
if (mysql_affected_rows()){
?>
<div id="tab1" class="tab_content">
<?php echo '<form action="" method="post" name="frm" onsubmit="return check">
<table class="tablesorter" cellspacing="0"> '; ?>
<thead>
<tr>
<th><a style="text-decoration: none;font-size:14px;font-weight: bold; color: blue" href="javascript:void(0);" id="link" onclick="slct()">All Select</a></th>
<th align= "left" >ID Number</th> <th></th>
<th align= "left" >USER NAME</th><label style="padding-right: 10px;padding-bottom: 10px;float:right " ><input style="color: red" type="submit" name="post" value="Selected Post"></label>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
while ($row = row($query)){
?>
<tr>
<td><input type="checkbox" name="checkbox[]" id="checkbox[]" ></td>
<td><?php echo ss($row["membName"]);?></td><td><input name="memb_id[]" type="hidden" value="<?php echo ss($row["memb_id"]);?>"></td>
<td><?php echo ss($row["memb_srnm"]);?></td><td><input name="memb_srnm[]" type="hidden" value="<?php echo ss($row["memb_srnm"]);?>"></td>
<td><input name="kur_id[]" type="hidden" value="<?php echo ss($_SESSION["kur_id"]);?>"></td>
</tr>
<?php }?>
</tbody>
<?php echo '</table></form>'; ?>
</div>
<?php }else{ ?>
<h4 class="alert_warning">Nobody Here :(( </h4>
<?php }?>
</div>
</article>
You're missing a quote on this line:
$check = mysql_query("SELECT * FROM basvurular WHERE memb_id='$memb_id'");
Also, to check whether a SELECT query returned any rows, you should use mysql_num_rows(), not mysql_affected_rows() -- the latter is only for queries that modify tables.
You should also check that the query is successful:
$check = mysql_query("SELECT * FROM basvurular WHERE memb_id='$memb_id")
or die(mysql_error());

Categories