Mala pomoć [PHP]

Pozz ljudi, trebam malu pomoć.

Imam dva fajla. Jedan je ajax.php a drugi profil.php.

*/ajax.php*/

$run = mysqli_query($con, "SELECT * FROM userslike WHERE uid='$id'ORDER BY slika_id DESC LIMIT ".$postnumbers." OFFSET ".$offset);

Potrebno je da uid=$id, a $id se uzima kod profil.php

Probao sam s include ali prikazuje da $id nije zadan.

$id kod profil.php je $id = intval($_GET[‘id’]);

P.S ovo je čitav kod.

Hvala na bilo kakvoj pomoći :slight_smile:

Probaj ovako uid=$id bez ovih navodnika…

Hvala ali ne moze :confused:

Lako za tutorijal, pošalji ti nama tvoj cjelokupni kod kako bi znali točno. Ovo u tutorijalu koristi druge varijable i query i sl.

Ako već koristiš ajax onda toj datoteci prosljeđuješ parametre preko javascripte ili poznate bliblioteke jQuery i sl. Kako ti ovdje prosljeđuješ tu vrijednost? Gdje ti je ta funkcija?
Zašto biš koristio include ako već ideš na ajax?
Možeš li nam reći cjelokupnu strukturu tvog projekta odnosno što sve koristiš kod ovog?

ako trebas ‘id’ iz adress bara sa get koristi, profile.php?id=2

if (isset($_GET['id']) && !empty($_GET['id']) && is_numeric($_GET['id']))
{
   $id = (int)$_GET['id'];
   // tvoj query di trebas id
   $run = mysqli_query($con, "SELECT * FROM userslike WHERE    uid='$id'ORDER BY slika_id DESC LIMIT ".$postnumbers." OFFSET ".$offset);

}

ali ako imas ‘id’ sa POST onda ga uzmi iz querija

// prvo si napravi query da izvuces id
$query = mysql_query("SELECT id FROM necega");
while($row = mysql_fetch_array($query)) {
      $id = (int)$row['id']';
}

$run = mysqli_query($con, "SELECT * FROM userslike WHERE uid='$id'ORDER BY slika_id DESC LIMIT ".$postnumbers." OFFSET ".$offset);

i onda sibas drugi query ispod

Ovo je kod za profil.php, znači ovdje se prikazuje sve.

  <html>
    <head>
    <link rel="stylesheet" type="text/css" href="style.css" />
    <script src="jquery.js"> </script>
    <script src="javascript.js"> </script>
    <script type="text/javascript" src="//use.typekit.net/vue1oix.js"></script>
    <script type="text/javascript">try{Typekit.load();}catch(e){}</script>
    
    <script>
    
    
    
    
    $(document).ready(function() {
    
    
    
    
    	$('#content').scrollPagination({
    
    
    
    
    		nop     : 10, // The number of posts per scroll to be loaded
    		offset  : 0, // Initial offset, begins at 0 in this case
    		error   : 'No More Posts!', // When the user reaches the end this is the message that is
    		                            // displayed. You can change this if you want.
    		delay   : 500, // When you scroll down the posts will load after a delayed amount of time.
    		               // This is mainly for usability concerns. You can alter this as you see fit
    		scroll  : true // The main bit, if set to false posts will not load as the user scrolls. 
    		               // but will still load if the user clicks.
    		
    	});
    	
    });
    
    
    
    
    </script>
    </head>
    
    <body>
    
    <?php
    /* OVAJ $id treba da bude poslan kod ajax.php gdje ce tamo biti SELECT * WHERE id=$id */
    if (isset($_GET['id']))
    {
    $id=$_GET['id'];
    }
    
    echo "<div id='content'></div>";
    
    ?>
    
    </body>
    </html>

Drugi kod je za ajax.php

<?php
include ('profil.php');

mysql_connect('xxx', 'xxx', 'xxx') or die();
mysql_select_db('xxx');
 
$offset = is_numeric($_POST['offset']) ? $_POST['offset'] : die();
$postnumbers = is_numeric($_POST['number']) ? $_POST['number'] : die();
 
 
$run = mysql_query("SELECT * FROM userslike WHERE uid='.$id.' ORDER BY slika_id DESC LIMIT ".$postnumbers." OFFSET ".$offset);
 
 
while($row = mysql_fetch_array($run)) {
     
    $content =$row['slika'];
     echo "<a class='example-image-link' href='$content' data-lightbox='example-1'><img class='example-image' src='$content' alt='thumb-1' width='206' height='206'/></a>";
 
}

?>

Evo ti kod meni radi sve na localhostu ajax.php

<?php

mysql_connect('localhost', 'root', '') or die(mysql_error());
mysql_select_db('cms2');

$offset = is_numeric($_POST['offset']) ? $_POST['offset'] : die();
$postnumbers = is_numeric($_POST['number']) ? $_POST['number'] : die();

// query da dobijes id od svih usera
$get_id = mysql_query("SELECT user_id FROM users");

while ($row1 = mysql_fetch_array($get_id))
{
    $id = $row1['user_id']; // ovo je user id

    $run = mysql_query("SELECT * FROM users WHERE user_id = '".$id."' ORDER BY user_id DESC LIMIT ".$postnumbers." OFFSET ".$offset)  or die(mysql_error());

while($row = mysql_fetch_array($run)) {
	
	$content = substr(strip_tags($row['username']), 0, 500);
	
	// tu si ispravi kad kliknes na username na popisu on ti ide na profile.php?id od korisnika kojeg si kliknio
	echo '<h1><a href="profile.php?id='.$row['user_id'].'">'.$row['username'].'</a></h1><hr />';

    }
}


?>

evo ti i profile.php da ti prikazuje samo 1 unos na koji kliknes tamo

<?php

if (isset($_GET['id']) && !empty($_GET['id']) && is_numeric($_GET['id']))
{

$id = (int)$_GET['id'];

mysql_connect('localhost', 'root', '') or die(mysql_error());
mysql_select_db('cms2');

// query da dobijes podatke od korisnika
$get_data = mysql_query("SELECT user_id, username, first_name, last_name, email FROM users WHERE user_id = '".$id."'") or die(mysql_error());


while ($row = mysql_fetch_array($get_data))
{
	// podatci koje oces da ti ispise
	$username = strip_tags($row['username']);
	$fname = strip_tags($row['first_name']);
	$lname = strip_tags($row['last_name']);
	$email = strip_tags($row['email']);
	?>
           <!-- profil od korisnika di je id iz baze = id iz adress bara -->
	    <h1><?php echo $username; ?> - profile<h1>
	<hr />

	Username : <?php echo $username; ?><br />
	Full name : <?php echo $fname . ' ' . $lname; ?><br />
	Email : <?php echo $email; ?>

	<?php 
        }
    } 
   else 
    { 
header('Location: index.php');
exit();
}

?>
1 Like

@mlukac​89 hvala na zalaganju i pomoći puno. Prije nego si napisao ovo ja sam riješio problem tako što sam na profil.php kod uzimanja id stavio session i taj session sam prenio na ajax.php.

/*profil.php*/
if(isset($_GET['id']))
{
$id = intval($_GET['id']);

session_start();
$_SESSION['id'] = $id;
}