Selecting a random photo and profile from a database.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
greree
Forum Newbie
Posts: 15
Joined: Sun Dec 14, 2003 10:34 am

Selecting a random photo and profile from a database.

Post by greree »

I'm trying to modify a script I found on the internet. In its original form, it picks two photos and profiles, one man and one woman, from a database and displays it on a web page. I want it to pick four photos and profiles, two each, from the database. The problem I'm having is that it picks the same two profiles for each gender. (i.e. The two male profiles are the same person, as is the two female profiles.) I want it to pick different men and different women.

I know very little about php. Mostly I solve problems by changing things and seeing what the results are. But this one has me stumped.


Here's the code.

Code: Select all

<td width="100%" valign="top">
				<table cellpadding="0" cellspacing="0">
        <tr valign="top">
          <td width="110"><a href="index.php?page=view_profile&id=<? echo $female&#1111; id ] ?>"><?
                  $fPhoto = $female&#1111;filename_1];
                  if($fPhoto != "")
				  &#123;
                    echo sysGetSmallImage("photos/$fPhoto", "");
  				  &#125;
			      else
				  &#123;
				  ?>
				  <img src="images/default_photo.gif" width="100" height="100">
				  <? &#125; ?></a>
          </td>
           <td width="100%">
                            <font color="#000000">&nbsp;Name:&nbsp;</font><? echo $female&#1111;login]; ?><br>
				<font color="#000000">&nbsp;Age:&nbsp;</font> <? echo $femaleage; ?><br>
				<font color="#000000">&nbsp;City:&nbsp;</font><? echo $female&#1111; city ]; ?><br>
				<font color="#000000">&nbsp;State:&nbsp;</font><? echo $female&#1111; state ]; ?><br>
				<font color="#000000">&nbsp;Seeking:&nbsp;</font><? echo $female&#1111; looking_for ]; ?><br>
            <br>
          </td>
				</tr>
        <tr valign="top">
          <td width="110"><a href="index.php?page=view_profile&id=<? echo $male&#1111; id ] ?>"><?
                  $fPhoto = $male&#1111;filename_1];
                  if($fPhoto != "")
				  &#123;
                    echo sysGetSmallImage("photos/$fPhoto", "");
  				  &#125;
			      else
				  &#123;
				  ?>
				  <img src="images/default_photo.gif" width="100" height="100">
				  <? &#125; ?></a>
          </td>
				<td width="100%">
                            <font color="#000000">&nbsp;Name:&nbsp;</font><? echo $male&#1111;login]; ?><br>
				<font color="#000000">&nbsp;Age:&nbsp;</font> <? echo $maleage; ?><br>
				<font color="#000000">&nbsp;City:&nbsp;</font><? echo $male&#1111; city ]; ?><br>
				<font color="#000000">&nbsp;State:&nbsp;</font><? echo $male&#1111; state ]; ?><br>
				<font color="#000000">&nbsp;Seeking:&nbsp;</font><? echo $male&#1111; looking_for ]; ?><br>
            <br>
          </td>
				</tr>
      </table>
				<table cellpadding="0" cellspacing="0">
        <tr valign="top">
          <td width="110"><a href="index.php?page=view_profile&id=<? echo $female&#1111; id ] ?>"><?
                  $fPhoto = $female&#1111;filename_1];
                  if($fPhoto != "")
				  &#123;
                    echo sysGetSmallImage("photos/$fPhoto", "");
  				  &#125;
			      else
				  &#123;
				  ?>
				  <img src="images/default_photo.gif" width="100" height="100">
				  <? &#125; ?></a>
          </td>
				<td width="100%">
                             <font color="#000000">&nbsp;Name:&nbsp;</font><? echo $female&#1111;login]; ?><br>
				<font color="#000000">&nbsp;Age:&nbsp;</font> <? echo $femaleage; ?><br>
				<font color="#000000">&nbsp;City:&nbsp;</font><? echo $female&#1111; city ]; ?><br>
				<font color="#000000">&nbsp;State:&nbsp;</font><? echo $female&#1111; state ]; ?><br>
				<font color="#000000">&nbsp;Seeking:&nbsp;</font><? echo $female&#1111; looking_for ]; ?><br>
            <br>
          </td>
				</tr>
        <tr valign="top">
          <td width="110"><a href="index.php?page=view_profile&id=<? echo $male&#1111; id ] ?>"><?
                  $fPhoto = $male&#1111;filename_1];
                  if($fPhoto != "")
				  &#123;
                    echo sysGetSmallImage("photos/$fPhoto", "");
  				  &#125;
			      else
				  &#123;
				  ?>
				  <img src="images/default_photo.gif" width="100" height="100">
				  <? &#125; ?></a>
          </td>
				<td width="100%">
                             <font color="#000000">&nbsp;Name:&nbsp;</font><? echo $male&#1111;login]; ?><br>
				<font color="#000000">&nbsp;Age:&nbsp;</font> <? echo $maleage; ?><br>
				<font color="#000000">&nbsp;City:&nbsp;</font><? echo $male&#1111; city ]; ?><br>
				<font color="#000000">&nbsp;State:&nbsp;</font><? echo $male&#1111; state ]; ?><br>
				<font color="#000000">&nbsp;Seeking:&nbsp;</font><? echo $male&#1111; looking_for ]; ?><br>
            <br>
          </td>
				</tr>
      </table>


				</td>
If you need more information let me know. Thanks.
User avatar
MrNonchalant
Forum Commoner
Posts: 29
Joined: Wed Jul 17, 2002 2:15 am

Post by MrNonchalant »

That isn't the full code. There's variables that you're working with that weren't sent in the code you you have there. Until I can see the full code there's nothing I, nor anyone, can do.
greree
Forum Newbie
Posts: 15
Joined: Sun Dec 14, 2003 10:34 am

Post by greree »

The code I sent is part of a page called index.ihtml. When you load index.php it includes index.ihtml and index.pml, along with other pages, and these pages include other pages. Rather than post the entire script, could you give me some info on what information you need? Thanks.

As far as I can tell, $male and $female needs to be random, but I don't have a clue as to how this script picks them. What would I look for?
User avatar
MrNonchalant
Forum Commoner
Posts: 29
Joined: Wed Jul 17, 2002 2:15 am

Post by MrNonchalant »

Look for $male and $female being set in the included files.

Code: Select all

$female&#1111;filename_1] = RandomGeneraterFunction(parameters);
It'll probably use rand() or a time function. What you do next depends on which one it uses.
greree
Forum Newbie
Posts: 15
Joined: Sun Dec 14, 2003 10:34 am

Post by greree »

Filename_1 is the field in the table dt_photos that contains the name of the photos.

This is in index.pml:

Code: Select all

<?
        $search_query = "SELECT *, p.id, p.gender FROM dt_profile AS p, dt_photos as f, dt_members as m WHERE (p.status='1' AND p.member_id=m.id and p.member_id=f.member_id AND f.filename_1 <> '' AND p.gender='Male') ORDER BY RAND()";
        $male = f(q($search_query));
	    $maleage = $male&#1111;age];

        $male&#1111; marital_status ] = f(q("SELECT name FROM dt_marital_status WHERE id='$male&#1111;marital_status]'"));
        $male&#1111; marital_status ] = $male&#1111; marital_status ]&#1111; name ];

        $male&#1111; country ] = f(q("SELECT name FROM dt_countries WHERE id='$male&#1111;country]'"));
        $male&#1111; country ] = $male&#1111; country ]&#1111; name ];

        $qWords = q("select name from dt_badwords");
        if($censor_on)
        &#123;
            $replace = "*";
            while($fWords = f($qWords))
            &#123;
                 for($i = 0; $i < strlen($fWords&#1111;name]); $i++)
                        $replace .= "*";

                 $male&#1111;general_info] = eregi_replace($fWords&#1111;name], $replace, $male&#1111;general_info]);
                 $male&#1111;appearance_info] = eregi_replace($fWords&#1111;name], $replace, $male&#1111;appearance_info]);
                 $male&#1111;looking_for_info] = eregi_replace($fWords&#1111;name], $replace, $male&#1111;looking_for_info]);
            &#125;
        &#125;
        
        $search_query = "SELECT *, p.id, p.gender FROM dt_profile AS p, dt_photos as f, dt_members as m WHERE (p.status='1' AND p.member_id=m.id and p.member_id=f.member_id AND f.filename_1 <> '' AND p.gender='Female') ORDER BY RAND()";
        $female = f(q($search_query));
	    $femaleage =  $female&#1111;age];

        $female&#1111; marital_status ] = f(q("SELECT name FROM dt_marital_status WHERE id='$female&#1111;marital_status]'"));
        $female&#1111; marital_status ] = $female&#1111; marital_status ]&#1111; name ];

        $female&#1111; country ] = f(q("SELECT name FROM dt_countries WHERE id='$female&#1111;country]'"));
        $female&#1111; country ] = $female&#1111; country ]&#1111; name ];

        $qWords = q("select name from dt_badwords");
        if($censor_on)
        &#123;
            while($fWords = f($qWords))
            &#123;
                 $replace = "*";
                 for($i = 0; $i < strlen($fWords&#1111;name]); $i++)
                        $replace .= "*";

                 $female&#1111;general_info] = eregi_replace($fWords&#1111;name], $replace, $female&#1111;general_info]);
                 $female&#1111;appearance_info] = eregi_replace($fWords&#1111;name], $replace, $female&#1111;appearance_info]);
                 $female&#1111;looking_for_info] = eregi_replace($fWords&#1111;name], $replace, $female&#1111;looking_for_info]);
            &#125;
        &#125;
  	    include "templates/index.ihtml";
?>
Does this have the information you need?
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

what the hell is a

.ihtml page
.pml page

ive never heard of stuff like this!?
greree
Forum Newbie
Posts: 15
Joined: Sun Dec 14, 2003 10:34 am

Post by greree »

Short for inline HTML, an advanced server-side scripting/programming language that functions as an extension to HTML, allowing the customization of dynamic Web sites that depend on interaction with databases. iHTML eliminates the need for Javascript or CGI programs as it provides the same functionality. See http://www.ihtml.com.

Files with the pml extension seem to be pieces of code that get inserted into php files.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

a web-site i am currently in the process of designing relies completely on database information and its a PHP file
Post Reply