Another PDO problem

  • (6 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5
  • Last »

77 Replies - 1812 Views - Last Post: 07 December 2013 - 04:03 AM Rate Topic: ***-- 2 Votes

#31 chris98  Icon User is offline

  • D.I.C Addict

Reputation: 34
  • View blog
  • Posts: 851
  • Joined: 06-July 13

Re: Another PDO problem

Posted 31 October 2013 - 10:52 AM

No, I mean when I change the first statement and add in $row['category'] = $category;

it doesn't work.It doesn't echo anything.

From:

$sql4 = "SELECT category FROM download_categories WHERE site = :site";
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
$ps = $pdo->prepare($sql4);
$ps->execute(array(':site'=>$site));
while ($row = $ps->fetch(PDO::FETCH_ASSOC)) {
echo '
<td class="upload">
  
  <a href="lister.php?category='.$row['category'].'&site='.$site.'"><b>'.$row['category'].'</a>
</td>
<td class="upload">



to

$sql4 = "SELECT category FROM download_categories WHERE site = :site";
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
$ps = $pdo->prepare($sql4);
$ps->execute(array(':site'=>$site));
while ($row = $ps->fetch(PDO::FETCH_ASSOC)) {
$category = $category;
echo '
<td class="upload">
  
  <a href="lister.php?category='.$row['category'].'&site='.$site.'"><b>'.$row['category'].'</a>
</td>
<td class="upload">



(This is only a small fraction, which is why I haven't closed it with a '}' and the '";'.)
Was This Post Helpful? 0
  • +
  • -

#32 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3554
  • View blog
  • Posts: 10,332
  • Joined: 08-June 10

Re: Another PDO problem

Posted 31 October 2013 - 10:55 AM

whatís line #6 supposed to do? the first time you access the category value is line #10 and even then you donít save it anywhere.

maybe you mix it up from when I used PDO::FETCH_COLUMN ? (which is IMHO still the better way to do thing with this query.)
Was This Post Helpful? 1
  • +
  • -

#33 chris98  Icon User is offline

  • D.I.C Addict

Reputation: 34
  • View blog
  • Posts: 851
  • Joined: 06-July 13

Re: Another PDO problem

Posted 31 October 2013 - 11:10 AM

It's for the next select, where I select the total downloads from that category:

$sql5 = "SELECT COUNT(*) AS id FROM downloads WHERE  category = :category AND site = :site";
$ps = $pdo->prepare($sql5);
$ps->execute(array(':site'=>$site,
':category'=>$category));
foreach ($ps as $row)
{  echo "

<td class='upload'>
  
  <b>".$row['id']."</b>
</td>";



Without defining the $category, I don't know how to get this query to work.
Was This Post Helpful? 0
  • +
  • -

#34 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3554
  • View blog
  • Posts: 10,332
  • Joined: 08-June 10

Re: Another PDO problem

Posted 31 October 2013 - 02:07 PM

but then you would need to assign a value to $category, like $row['category']. doing $category = $category; is equivalent to doing $category; which is equivalent to doing .

This post has been edited by Dormilich: 31 October 2013 - 02:08 PM

Was This Post Helpful? 1
  • +
  • -

#35 chris98  Icon User is offline

  • D.I.C Addict

Reputation: 34
  • View blog
  • Posts: 851
  • Joined: 06-July 13

Re: Another PDO problem

Posted 01 November 2013 - 01:49 AM

Dormilich said:

but then you would need to assign a value to $category, like $row['category'].


That's exactly what I'm trying to do - but it stops the rest of the script from echoing the categories when I do.

$row['category'] = $category;

I don't understand why.

This post has been edited by chris98: 01 November 2013 - 01:50 AM

Was This Post Helpful? 0
  • +
  • -

#36 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3554
  • View blog
  • Posts: 10,332
  • Joined: 08-June 10

Re: Another PDO problem

Posted 01 November 2013 - 01:56 AM

Quote

I don't understand why.

thatís simple. you assign to null (the value of an unassigned variable) to $row['category'] instead of $row['category'] to $category.
Was This Post Helpful? 1
  • +
  • -

#37 chris98  Icon User is offline

  • D.I.C Addict

Reputation: 34
  • View blog
  • Posts: 851
  • Joined: 06-July 13

Re: Another PDO problem

Posted 01 November 2013 - 02:01 AM

Yes, but even when I do this, the values still aren't echoed.But as soon as I remove the $row['category'] = $category; it works??

$sql4 = "SELECT category FROM download_categories WHERE site = :site";
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
$ps = $pdo->prepare($sql4);
$ps->execute(array(':site'=>$site));
while ($row = $ps->fetch(PDO::FETCH_ASSOC)) {
//below here
$row['category'] = $category;
//above here
echo '
<td class="upload">
  
  <a href="lister.php?category='.$row['category'].'&site='.$site.'"><b>'.$row['category'].'</a>
</td>
<td class="upload">



To me, that should make no difference whatsoever, as I am only defining a variable - but it honestly stops the whole script from echoing the categories.The five boxes still appear, but they are empty.
Was This Post Helpful? 0
  • +
  • -

#38 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3554
  • View blog
  • Posts: 10,332
  • Joined: 08-June 10

Re: Another PDO problem

Posted 01 November 2013 - 02:07 AM

maybe I havenít been clear enough ... time to var_dump()
// ...
while ($row = $ps->fetch(PDO::FETCH_ASSOC)) {
  // check before
  echo "row: ";
  var_dump($row['category']);
  echo " cat: ";
  var_dump($category);

  $row['category'] = $category;

  // check after
  echo "row: ";
  var_dump($row['category']);
  echo " cat: ";
  var_dump($category);

echo '
  // etc.


Was This Post Helpful? 0
  • +
  • -

#39 chris98  Icon User is offline

  • D.I.C Addict

Reputation: 34
  • View blog
  • Posts: 851
  • Joined: 06-July 13

Re: Another PDO problem

Posted 01 November 2013 - 02:13 AM

Before:

row: string(9) "Kingmaker" cat: NULL 
test1 
test2 
FILENAME 
row: string(10) "Custom War" cat: NULL 
test1 
test2 
FILENAME 
row: string(12) "Peace Custom" cat: NULL 
test1 
test2 
FILENAME 
row: string(10) "Free Build" cat: NULL 
test1 
test2 
FILENAME 
row: string(13) "Miscellaneous" cat: NULL



After:

row: NULL cat: NULL 
test1 
test2 
FILENAME 
row: NULL cat: NULL 
test1 
test2 
FILENAME 
row: NULL cat: NULL 
test1 
test2 
FILENAME 
row: NULL cat: NULL 
test1 
test2 
FILENAME 
row: NULL cat: NULL 


This post has been edited by chris98: 01 November 2013 - 02:15 AM

Was This Post Helpful? 0
  • +
  • -

#40 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3554
  • View blog
  • Posts: 10,332
  • Joined: 08-June 10

Re: Another PDO problem

Posted 01 November 2013 - 02:19 AM

do you see now, what the problem with your assignment is?
Was This Post Helpful? 0
  • +
  • -

#41 chris98  Icon User is offline

  • D.I.C Addict

Reputation: 34
  • View blog
  • Posts: 851
  • Joined: 06-July 13

Re: Another PDO problem

Posted 01 November 2013 - 02:22 AM

Yes, it's the category - but I don't see how as it shows it in the var_dump()


It can't be - I'm not fetching for a category, I'm only fetching for a site.

This post has been edited by chris98: 01 November 2013 - 02:23 AM

Was This Post Helpful? 0
  • +
  • -

#42 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3554
  • View blog
  • Posts: 10,332
  • Joined: 08-June 10

Re: Another PDO problem

Posted 01 November 2013 - 02:27 AM

of course you fetch a category, thatís what your SQL says.
Was This Post Helpful? 1
  • +
  • -

#43 chris98  Icon User is offline

  • D.I.C Addict

Reputation: 34
  • View blog
  • Posts: 851
  • Joined: 06-July 13

Re: Another PDO problem

Posted 01 November 2013 - 02:32 AM

So the question is, why is it not working?

And why has it got something to do with just defining a variable?


Could it be something to do with my fetching method?
Was This Post Helpful? 0
  • +
  • -

#44 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3554
  • View blog
  • Posts: 10,332
  • Joined: 08-June 10

Re: Another PDO problem

Posted 01 November 2013 - 02:36 AM

Quote

So the question is, why is it not working?

if you mean the assignment, itís not working because this is the only spot where you think the assignment works backwards.
Was This Post Helpful? 0
  • +
  • -

#45 chris98  Icon User is offline

  • D.I.C Addict

Reputation: 34
  • View blog
  • Posts: 851
  • Joined: 06-July 13

Re: Another PDO problem

Posted 01 November 2013 - 02:39 AM

How does it work backwards?

What do you mean by that?

This post has been edited by chris98: 01 November 2013 - 02:40 AM

Was This Post Helpful? 0
  • +
  • -

  • (6 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5
  • Last »