Jump to content

Recommended Posts

Need help with inserting a count at the end of my text.

 

2 tables

 

Artist

artID

name

ect

 

Images

imgID

artID

etc

 

I have a list that pulls all the artists from the Artist table alphabetically. It also displays the artist image if available. I need help with adding the number of images that I have for each artist.

 

I am thinking I need to count the number of time the artid shows up in my Images table, right? And if so how do I incorporate it into the code below?

 

JPG ArtistName, Birth Date – Date of Death, # of images on file

 

 

 <?php

      echo "<div id='title'><h1>Browse by Artist Alphabetically</h1></div>";

      echo "<div id='search2'>";
      echo "
      <a href='artistHTML.php?alpha=A'>A</a>
      <a href='artistHTML.php?alpha=B'>B</a> 
      <a href='artistHTML.php?alpha=C'>C</a> 
      <a href='artistHTML.php?alpha=D'>D</a> 
      <a href='artistHTML.php?alpha=E'>E</a> 
      <a href='artistHTML.php?alpha=F'>F</a> 
      <a href='artistHTML.php?alpha=G'>G</a> 
      <a href='artistHTML.php?alpha=H'>H</a> 
      <a href='artistHTML.php?alpha=I'>I</a> 
      <a href='artistHTML.php?alpha=J'>J</a> 
      <a href='artistHTML.php?alpha=K'>K</a> 
      <a href='artistHTML.php?alpha=L'>L</a> 
      <a href='artistHTML.php?alpha=M'>M</a> 
      <a href='artistHTML.php?alpha=N'>N</a> 
      <a href='artistHTML.php?alpha=O'>O</a> 
      <a href='artistHTML.php?alpha=P'>P</a> 
      <a href='artistHTML.php?alpha=Q'>Q</a>
      <a href='artistHTML.php?alpha=R'>R</a>
      <a href='artistHTML.php?alpha=S'>S</a>
      <a href='artistHTML.php?alpha=T'>T</a>
      <a href='artistHTML.php?alpha=U'>U</a>
      <a href='artistHTML.php?alpha=V'>V</a>
      <a href='artistHTML.php?alpha=W'>W</a>
      <a href='artistHTML.php?alpha=X'>X</a>
      <a href='artistHTML.php?alpha=Y'>Y</a>
      <a href='artistHTML.php?alpha=Z'>Z</a><br><br><br>";

      echo "</div>";

$search=$_GET["alpha"];
  if ($search != "")
    {
      $result = mysql_query("SELECT * FROM artist WHERE lastname like '$search%' ORDER by lastname");
      $count = count(0);
        while ($r=mysql_fetch_array($result))
          {	
            $fullName=$r["fullName"];
            $dob=$r["dob"];
            $dod=$r["dod"];
            $nationality =$r["nationality"];
            $choosen_medium=$r["artForm"];
            $artid=$r["artid"];

      //display the row
            echo "<div id='search2'>";
              echo $count++;
              echo ". <img src='../image/$artid/$artid.jpg' width='150' height='150' border='0'><a href='formArtist.php?artid=$r[artid]'>".$fullName."</a>, ".$nationality.", ".$dob."-".$dod."</div>";
          }
}
?>

 

A version of count

 

    $query = "SELECT artid from image where artid.image=artid.artist";
      $result = mysql_query($query);
      $totimg = mysql_num_rows($result);

      echo "Images - $totimg<br>";

 

 

I think I need to use a join but not sure where to go from there?

 

 

$result = mysql_query("SELECT artID.artist, fullName.artist, dob.artist, dob.artist, artID.image FROM artist, image WHERE lastname like '$search%' ORDER by lastname");

Link to comment
https://forums.phpfreaks.com/topic/164132-need-help-with-count/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.