mjurmann Posted July 12, 2007 Share Posted July 12, 2007 Hello. I am trying to figure out if it is possible to create a loop with a counter and if the loop iteration is equal to a $_POST['x'] variable, then echo out information from a recordset that also includes the counter variable. This might not make much sense so just look at the code: <?php $featureCount = 0;?> // initialize $featureCount counter <?php do { ?> // being loop <?php $featureCount++;?> // add 1 to the variable $featureCount <?php if ($_POST['featureID1'] == $featureCount) { ?> // if posted number is equal to the $featureCount integer <?php echo $row_FeatureID;?><?php echo $featureCount;?><?php echo ['featureName']; ?> // echo the FeatureID query with the $featureCount current value added to the query name. I've created 20 different queries each ending with 1-20 (FeatureID1 - FeatureID20). Once the query is found with the number that matches the current $featureCount value, it will ech out the ['featureName'] field from that specific query. <?php } while ($featureCount < 20;?> So my question is, is this possible? I've been going at this all day long and can't get it. My head is ready to explode...please help :/ Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 12, 2007 Share Posted July 12, 2007 i dont read the code but try for($ctr=0$ctr<=put here the value;$ctr++) { if ($_POST['x'] ==$ctr) { echo "here".$ctr; } } Quote Link to comment Share on other sites More sharing options...
mjurmann Posted July 12, 2007 Author Share Posted July 12, 2007 Thats a for loop and didn't really address my issue, thanks though... Quote Link to comment Share on other sites More sharing options...
JayBachatero Posted July 12, 2007 Share Posted July 12, 2007 You want something like this? Also there is no need to leave and enter php each line. <?php $featureCount = 0; do { // Is the posted number equal to the $featureCount? if (isset($_POST['featureID1']) && (is_numeric($_POST['featureID1']) && $_POST['featureID1'] == $featureCount)) { // Get the data from the database $request = mysql_query(" SELECT featureName FROM {TABLE NAME} WHERE FeatureID = $featureCount") or die(mysql_error()); // Loop through the results and echo them. while ($row = mysql_fetch_assoc($request)) { echo 'FeatureID = ' . $row['FeatureID'] . '<br /> FeatureCount = ' . $featureCount . '<br /> FeatureName = ' . $roe['featureName'] . '<br />'; } mysql_free_result($request); $featureCount++; } while ($featureCount < 20); ?> Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted July 12, 2007 Share Posted July 12, 2007 You are missing a substantial amount of code that defines several of your variables from your example...where does $row_FeatureID come from? "echo ['featureName'];" isn't even valid syntax. Why are you constantly going in and out of php? E.g. <?php echo "a"; ?><?php echo "b"; ?> etc. Just use one set of php tags... <?php $featureCount = 0; while ($featurecount < 20) [ $featureCount++; if ($_POST['featureID1'] == $featureCount) { echo "featureID1 matches featureCount"; } } ?> Quote Link to comment 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.