/    Sign up×
Community /Pin to ProfileBookmark

Database display

Hell guys i am coding a web site for ads , and now i am taking a part where i have to display my database records to my webpage , so this is my database [ATTACH=CONFIG]17107[/ATTACH] now there is only 2 rows as a sample but later will by much more like 100-1000 so now i need to display them on the web page like picture , title and something and other information i have diferent table for picture to save so this is just an information about ad , and i need an idea how should i do so i dont need a codes or something just asking you guys an idea how to do so ?

[canned-message]attachments-removed-during-migration[/canned-message]

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMay 09.2016 — In PHP it's probably most commonly done via a while() loop on a DB query result set. E.g.:
[code=php]
$queryResult = $db->execute($your_sql_statement);
while($row = $queryResult->fetch()) {
echo "<p>{$row['col_1']} <i>{$row['col_2']}</i></p>n";
}
[/code]
Copy linkTweet thisAlerts:
@yahoo5000authorMay 10.2016 — In PHP it's probably most commonly done via a while() loop on a DB query result set. E.g.:
[code=php]
$queryResult = $db->execute($your_sql_statement);
while($row = $queryResult->fetch()) {
echo "<p>{$row['col_1']} <i>{$row['col_2']}</i></p>n";
}
[/code]
[/QUOTE]

okay that was good for me i think to do it with for loop but did you way , but the thing i want is something like this :

[ATTACH=CONFIG]17109[/ATTACH]

and i get only like text from data base , i am not very familiar with php styling but i do not think that i can do it with only php so now question is how to include a html into a php code cuz now i have a simple code :
<?php

$userid = $_SESSION["userid"];
$sql = "SELECT * FROM posts WHERE userid='$userid' ";
$res = mysqli_query($connect,$sql);
$rowcount = mysqli_num_rows($res);
while ($row = mysqli_fetch_assoc($res)) {
echo "<p>".$row["title"]."n".$MainPhoto."</p>n";
}

?>[/QUOTE] with no style at all


[canned-message]attachments-removed-during-migration[/canned-message]
Copy linkTweet thisAlerts:
@yahoo5000authorMay 10.2016 — In PHP it's probably most commonly done via a while() loop on a DB query result set. E.g.:
[code=php]
$queryResult = $db->execute($your_sql_statement);
while($row = $queryResult->fetch()) {
echo "<p>{$row['col_1']} <i>{$row['col_2']}</i></p>n";
}
[/code]
[/QUOTE]

okay that was good for me i think to do it with for loop but did you way ,but now i have a problem i have tables (images,posts)

posts is for all information and images are for a image of the post (for path) so now have the question how to select and use both of those tables hare is my code for now : <?php

$userid = $_SESSION["userid"];
$sql = "SELECT * FROM posts WHERE userid='$userid' ";
$res = mysqli_query($connect,$sql);
while ($row = mysqli_fetch_assoc($res)) {
?>
<p class="ads" >
<a href=""><?php echo $row["title"]; ?></a><br>
<a href=""><img src=""></a>
</p>
<?php
}

?>[/QUOTE]
Copy linkTweet thisAlerts:
@ginerjmMay 10.2016 — You need to learn some html, some CSS and how to code. We are here to HELP you when you attempt that, but we are NOT here to write your code for you. So - make the effort and post what you have problems with and THEN we can help you out. If you just want someone to do your work, there is another forum of 'for hire' people.
Copy linkTweet thisAlerts:
@yahoo5000authorMay 10.2016 — Dont need anything solved by joining a tables and use $row to extract data :

<?php

$userid = $_SESSION["userid"];
$sql = "SELECT * FROM posts p JOIN images i ON p.id = i.postid WHERE userid='$userid' ";
$res = mysqli_query($connect,$sql);
while ($row = mysqli_fetch_assoc($res)) {
?>
<div id="ads">
<div id="titlepic">
<a href=""><?php echo $row["title"]; ?></a><br>
<a href=""><img src="<?php echo $row["path1"]; ?>" height="100px" width="150px"></a>
</div>
<div id="managead">
<a href="">Edit</a><br style="margin-bottom: 5px;">
<a href="">Delete</a><br style="margin-bottom: 5px;">
<a href="">Renew</a>
</div>
<div id="dates">
<b>Date Added:</b> <?php echo date('m/d/Y', $row["dateadded"]); ?><br>
<b>Renew Date:</b> <?php if($row["renewdate"] > 0){ echo date('m/d/Y', $row["renewdate"]); } ?><br>
<b>Location:</b> <?php echo $row["location"]; ?><br>
<b>Price:</b> <?php echo $row["price"]; ?><br>
</div>
</div>
<hr width="100%">
<?php[/QUOTE]
Copy linkTweet thisAlerts:
@yahoo5000authorMay 11.2016 — Have a new problem with a javascript :

Top:
[code=php]if (isset($_GET['delete'])){
$postid = $_GET["id"];
$sql = "DELETE p,i FROM posts p JOIN images i ON p.id = i.postid WHERE postid='$postid' ";
$res = mysqli_query($connect,$sql);
}
[/code]

script :
[code=html]<script>
function myFunction() {
var txt;
var r = confirm("Are you sure you want to delete ?");
if (r == true) {
window.location.href = 'ads.php?delete=true&id=<?php echo $row["postid"]; ?>';
} else {

}
}
</script>[/code]

and main code :[code=php] <?php

$userid = $_SESSION["userid"];
$sql = "SELECT * FROM posts p JOIN images i ON p.id = i.postid WHERE userid='$userid' ";
$res = mysqli_query($connect,$sql);
while ($row = mysqli_fetch_assoc($res)) {
?>
<div id="ads">
<div id="titlepic">
<a href=""><?php echo $row["title"]; ?></a><br>
<a href=""><img src="<?php echo $row["path1"]; ?>" height="100px" width="150px"></a>
</div>
<div id="managead">
<a href="ads.php?edit=true&id=<?php echo $row["postid"]; ?>" >Edit</a><br style="margin-bottom: 5px;">
<a href="ads.php?delete=true&id=<?php echo $row["postid"]; ?>" onclick="myFunction()" >Delete</a><br style="margin-bottom: 5px;">
<a href="ads.php?renew=true&id=<?php echo $row["postid"]; ?>">Renew</a>
</div>
<div id="dates">
<b>Date Added:</b> <?php echo date('m/d/Y H:i', $row["dateadded"]); ?><br>
<b>Renew Date:</b> <?php if($row["renewdate"] > 0){ echo date('m/d/Y H:i', $row["renewdate"]); } ?><br>
<b>Location:</b> <?php echo $row["location"]; ?><br>
<b>Price:</b> <?php echo $row["price"]."&pound"; ?><br>

</div>
</div>
<hr width="100%">
<?php[/code]


so the problem is no meter what i press ok or cancel the ad will by deleted anyway ,so i need to edit a javascript somehow to get the result only if it ok
Copy linkTweet thisAlerts:
@NogDogMay 11.2016 — <MOD>Please note the changes I made to the preceding post, replacing the [noparse] tags with applicable [code=php] and [code=html][/noparse] tags. Help us help you, by using the force ... I mean forum ... wisely.</MOD>

http://www.webdeveloper.com/forum/misc.php?do=bbcode (bbcode tags)
×

Success!

Help @yahoo5000 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...