Jump to content

Recommended Posts

Depending on the version of mysql, you might be able to get away with doing it all in one query.

 

Regardless, here's a decent way to do it, using 2 queries that will work on nearly any version of MySQL:

$result = '1,2,3';//in reality, you're going to get this through a query instead, not assigning it by hand.

$newQuery = 'SELECT * FROM table2 WHERE somevalue IN ('.$result.')';

 

You could also explode it as mentioned above, and individually deal with the records in a loop.

 

E.g.

$result = '1,2,3';//in reality, you're going to get this through a query instead, not assigning it by hand.
$resultArray = explode(',',$result);
for($i=0;$i<sizeof($resultArray);$i++) {
  $newQuery = 'SELECT * FROM table2 WHERE somevalue = '.$resultArray[$i];
}

Link to comment
https://forums.phpfreaks.com/topic/229082-separating-by-comma/#findComment-1180602
Share on other sites

This is what I have and for the matchTypeID, titleID, and stipulationID all three of these could/could not have values and if they do then they could possibly have just one integer or they could have more than one separated by that comma.

 

<?php		
$count=1;
$query = "SELECT 
    eventSegments.matchTypeID,
    eventSegments.titleID,
    eventSegments.stipulationID, 
    eventSegments.segmentTitle, 
    eventSegments.preview
FROM 
    eventSegments 
WHERE 
    eventSegments.eventID = '$eventID' AND eventSegments.type ='match' 
ORDER BY 
    eventSegments.sortOrder";
$result = mysql_query ($query); 		
$numrows = mysql_numrows($result);
while ($row = mysql_fetch_assoc($result)) {
    $fieldarray=array('titleName','matchType','stipulation','segmentTitle','preview');
    foreach ($fieldarray as $fieldlabel) {
    	if (isset($row[$fieldlabel])) { 
    		${$fieldlabel} = $row[$fieldlabel];
    	}
    }
    if ($count != $numrows) {
    	print "<h2 class=matchnum>Match ".$count."</h2>\n";
    } else {
    	print "<h2 class=matchnum>Main Event</h2>\n";
    }

    
    if (!empty($stipulation)) {
        echo '<h3 class="title">';
    
        if (!empty($titleName)) {
            echo $titleName . ' ';
        }
    
        echo 'Championship Match</h3>';
    }
                
    print "<h3 class=match>".$segmentTitle."</h3>\n";
    if (!empty($preview)) { print "<p class=blurb>".nl2br($preview)."</p>\n"; }
$count++;
}
    print "<p class=cardchange>Card Subject To Change.</p>\n";
} else {
    print "<p>No Forthcoming Events booked.</p>\n";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/229082-separating-by-comma/#findComment-1180607
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.