Jump to content

Recommended Posts

I basically want to display data depending which row it's pulled from .... here's a basic idea

 

if data is from row "title" -> display title, artist and album details

if data is from row "album" -> display just one row for unique album titles (the row will pull multiple as the row will contain the same album title 20+ times)

if data is from row "artist" -> the same as if displaying album details

 

Hope that makes some logical sense, really really stuck on finding out how to achieve this ... any pointers would be great or even the code I'd need to use!

 

Ta :)

 

HJ

Sorry, I know it does seem confusing, I don't have any code at the moment as I really don't know how to format what I need to achieve.

 

Basically, it's a search form which autocompletes, so loads without pressing submit.  When you search, you can search for any text, it checks within three rows, title, album and artist.  If the result pulls the data from title, it should show the title, artist and album, that works as default.  I want to extend it so that if the search matches within either the album or artist row, it only shows the album or artist title, however, because each album will contain more than one track, the same album will be listed 30+ times, thus pulling back 30+ of the same album title.  I need to make it so it only displays either artist or album just once each time.  There's the part I don't know how to code, to make the IF deal with which row the data has been pulled from.

 

Hope that makes things a bit easier to understand.

 

Cheers,

 

HJ

I have 80% of the code working, just trying to see if I can find a command which will achieve what I'm trying to do ... here's the code I have, this is where I've tried making all my changes.  the if / elseif / elseif are the ones I'm talking about, this code doesn't currently work but I'm hoping it's something fairly straightforward.

 

<?php
$SQL_FROM = 'songlist';
$SQL_WHERE = 'title';

$searchq		=	strip_tags($_GET['q']);
$getRecord_sql	=	'SELECT * FROM '.$SQL_FROM.' WHERE songtype = "S" AND title LIKE "%'.$searchq.'%" OR album LIKE "%'.$searchq.'%" OR artist LIKE "%'.$searchq.'%"';
$getRecord		=	mysql_query($getRecord_sql);
if(strlen($searchq)>0){
// ---------------------------------------------------------------- // 
echo '<ul>';
$row = mysql_fetch_array($getRecord);
if (!mysql_num_rows($getRecord)) {		
	echo "Sorry, I ain't got that!"; 
} else {
while ($row = mysql_fetch_array($getRecord)) {
	if (in_array($row['title'])) { echo "Title works"; echo '</ul>'; exit; }
	elseif (in_array($row['album'])) { echo "Album works"; echo '</ul>'; exit; }
	elseif (in_array($row['artist'])) { echo "Artist works"; echo '</ul>'; exit; }
?>
	<li><a href="playlist.php?search=<?php echo $row['title']; ?>&dcat=title">Title: <?php echo $row['title']; ?></a><small><a href="playlist.php?search=<?php echo $row['artist']; ?>&dcat=artist">Artist:  <?php echo $row['artist']; ?></a><a href="playlist.php?search=<?php echo $row['album']; ?>&dcat=album">Album: <?php echo $row['album']; ?></a></small></li>
<?php 
 } 
}
echo '</ul>';
?>
<?php } ?>

 

Any ideas on where I'm going wrong?  Hopefully the code shows more of what I'm attempting to do.

 

Cheers,

 

HJ

I know the in_array() is formatted wrong here, the question I need to ask is I'm pulling the info from the $row array, but I'm not entirely sure it's been created so it can be reused?  I keep getting a "Warning: in_array() [function.in-array]: Wrong datatype for second argument" error when trying to use

in_array($searchq,$row['title'])

 

Any suggestions on what I'm missing?

 

Thanks,

 

HJ

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.