Can I alter the $row->name1 number of a variable?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Can I alter the $row->name1 number of a variable?

Post by simonmlewis »

Because catid *IS* always the same, as this is the Edit page for the product. One product is assigned to one catid.
And no, an answer to this $variable issue has not been resolved.

I asked why that $row->{$prod} wasn't working, and no one has said "no it should be done like this...".
I've only been told "change all your code, so it works the way I do it".... not "yes, you need it to be like this to match the rest of your code.

If I cannot really get answer here, I'll just do it a longer way around, which I understand and which I know works for me, and avoids any further interuptions so the client can get on and deal with his products.

One of the issues with this forum (I don't find regularly, but often), is that people want to have someone change all their code that they understand.
While they probably know better, they must also appreciate that this code I have written, WORKS. I understand how it works, and why it is written like that.
So to utterly change it, would blow my mind, and take me even more time to learn right here and now.

99% of this page works. It's just this one variable issue that doesn't.

I keep getting quotes on my comments back, with a a reason they think it should be all ripped out and changed. No.

Imagine I am a deal selling a car. The wheel turns fine. The car works fine. Everyone is happy. But the wheel bolt won't fit. If the bolt can be adjusted to just go on, that's great. But I am not really going to take the wheel and tyre apart, take out all the bearings and wheel fitment and learn how it all works in there... when it WORKS. And it's just that bolt that needs filing, or a slightly different shaped bolt from a drawer is needed instead.

Odd analogy I grant you - but it's one I understand.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Can I alter the $row->name1 number of a variable?

Post by simonmlewis »

With a fresh morning head.. it's now working. Might have been a conflict with too many variables set before it.

Code: Select all

<table>
			";
			$count = 1;
			while ($count <= 4)
			{

      // sets $prod to be rating1...2..3..4 for $row->rating1..2..3..4
      $prod = "rating"."$count";
      
      // changes $ratingtitle to be ratingtitle1..2..3..4 to query Category fields.
			$ratingtitle = "ratingtitle"."$count";
			
			$rating = "ratingtitle"."$count";
			$querycat = ("SELECT $ratingtitle AS rowratingtitle FROM categories WHERE id =:catid");
      $resultcat = $pdo->prepare($querycat);
      $resultcat->execute(array(':catid' => $row->catid));
      while ($rowcat = $resultcat->fetch(PDO::FETCH_OBJ)) 
        {
        echo "<tr><td>$rowcat->rowratingtitle";
        }
			echo "</td><td><select name='$rating'>
			<option value='10'>10</option>
			<option value='20'"; if ($row->{$prod} == "20") { echo " selected='selected'";} echo ">2</option>
			<option value='30'"; if ($row->{$prod} == "30") { echo " selected='selected'";} echo ">3</option>
			<option value='40'"; if ($row->{$prod} == "40") { echo " selected='selected'";} echo ">4</option>
			<option value='50'"; if ($row->{$prod} == "50") { echo " selected='selected'";} echo ">5</option>
			<option value='60'"; if ($row->{$prod} == "60") { echo " selected='selected'";} echo ">6</option>
			<option value='70'"; if ($row->{$prod} == "70") { echo " selected='selected'";} echo ">7</option>
			<option value='80'"; if ($row->{$prod} == "80") { echo " selected='selected'";} echo ">8</option>
			<option value='90'"; if ($row->{$prod} == "90") { echo " selected='selected'";} echo ">9</option>
			<option value='100'"; if ($row->{$prod} == "100") { echo " selected='selected'";} echo ">10</option>
			</select></td></tr>";
			
			$count ++;
			}
		
		echo "</table>
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply