Hyperjase Posted June 12, 2010 Share Posted June 12, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/204596-do-different-things-if-data-pulled-from-different-rows/ Share on other sites More sharing options...
ignace Posted June 12, 2010 Share Posted June 12, 2010 Post your code as your explanation does not make much sense. Quote Link to comment https://forums.phpfreaks.com/topic/204596-do-different-things-if-data-pulled-from-different-rows/#findComment-1071248 Share on other sites More sharing options...
Hyperjase Posted June 13, 2010 Author Share Posted June 13, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/204596-do-different-things-if-data-pulled-from-different-rows/#findComment-1071367 Share on other sites More sharing options...
ignace Posted June 13, 2010 Share Posted June 13, 2010 You need Ajax. Your HTML will look something like: <input type="text" name="search" value="" onkeypress="findRecordsFor(this.value)"> Quote Link to comment https://forums.phpfreaks.com/topic/204596-do-different-things-if-data-pulled-from-different-rows/#findComment-1071372 Share on other sites More sharing options...
Hyperjase Posted June 13, 2010 Author Share Posted June 13, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/204596-do-different-things-if-data-pulled-from-different-rows/#findComment-1071384 Share on other sites More sharing options...
Hyperjase Posted June 14, 2010 Author Share Posted June 14, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/204596-do-different-things-if-data-pulled-from-different-rows/#findComment-1072073 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.