Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8779257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:44:31+00:00 2026-06-13T19:44:31+00:00

1) I have the below (include) to display random records from my db(phprealty) with

  • 0

1) I have the below (include) to display random records from my db(phprealty) with two union tables (phprealty_propert + phprealty_prop_img). The code is working without any problems. However, when I set the limit to 3, I get 2 records and that’s why I set the limit to 4 so I get 3 records. Shall I leave it as is?

2) Since i am new to PHP, do you think this code is vulnerable thus needs some kind of protection? if so, please advise what to do to protect the webpage when using PHP to display data.

Thank you in advance.

<?php
$pid = 3;
$myConnection = new mysqli("localhost", "root", "", "phprealty");
$sqlCommand = "SELECT phprealty_property.*, phprealty_prop_img.p_id, phprealty_prop_img.fn FROM phprealty_property INNER JOIN phprealty_prop_img ON phprealty_property.id = phprealty_prop_img.p_id WHERE phprealty_prop_img.def='1' AND phprealty_property.type = $pid"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());

$sqlCommand .= " ORDER BY RAND() LIMIT 0,4";
$result = mysqli_query($myConnection, $sqlCommand);

$Displayproperty = '';
$row = mysqli_fetch_array($result);
$id = $row["id"];
$title = $row["title"];
while ($row2 = mysqli_fetch_array($result)){
$img = $row2["fn"];
$thumb = 'th_' . $img;
$Displayproperty .= '
<div class="random">
<a href="display.php?id=' . $id . '"><img src="../falcon/listImgs/' . $thumb . '" />   </a></div>';
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:44:33+00:00Added an answer on June 13, 2026 at 7:44 pm

    Just delete

    $row = mysqli_fetch_array($result);
    

    then change these two lines

    $id = $row["id"];
    $title = $row["title"];
    

    into

    $id = $row2["id"];
    $title = $row2["title"];
    

    and put both lines after while statement.

    In your code right now, display.php will be showing always the same code, because $id does not change.

    Is your code working properly? First parameter on mysqli_query should be $sqlCommand, not $myConnection.

    If you can, try to not use root/empty_password on Mysql.

    Hope it helps,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some doubt on below code #include<stdio.h> int i=6; int main() { int
I have a code like this below in /root_project/main.cpp : #include theoraplayer/TheoraVideoClip.h unsigned int
I have two similar tables which have data I need to display in a
I have template function compare defined as below. #include<iostream> using namespace std; template<typename T>
I have a script snippet looks like below: <ItemGroup> <files Include=*.txt></files> </ItemGroup> <Message Text=@(files)>
I have below snippet of code in which TestClass is extending jPanel which is
I have below code: <a href=# id=@item.Id name=vote ><img src=/Content/images/021.png style=float:left alt= /></a> which
I am designing and implementing a class where I have to include two initialization
See the code below - I am trying to include inline svg in my
I have a code (see it below). It works perfectly in Firefox: it saves

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.