Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

problem with a mysql query (not db related)

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
c0p0n
Smarty n00b


Joined: 15 Jul 2003
Posts: 4

PostPosted: Tue Jul 15, 2003 2:41 pm    Post subject: problem with a mysql query (not db related) Reply with quote

it is not a database problem, first of all.
I am developing a website using PHP, MySQL and Smarty (so original Wink) and all is running PERFECTLY.
but I have a little problem that I do not understand. I create an array with a function from a DB query, on this way:
Code:

$query= "SELECT Foro_titulo, Usuario_nombre, Foro_texto, DATE_FORMAT(Foro_fecha, '%e'), Foro_hora FROM fy_foro WHERE ID_topic = {$topic} ORDER BY ID_respuesta";
$data = create_array($query);

the function create_array is:
Code:

function create_array($query)
{

$result= mysql_query($query);          
$array_final = array();             
while ($query_result= mysql_fetch_array($result))
      array_push($array_final, $query_result);       
return ($array_final);

}
.
Then, I pass the variable to smarty on the usual way:
$smarty->assign('data', $data);

and, on the template, I put the following code. I've cut aesthetics down, to avoid overloading with code that doesn´t make sense on the problem:
Code:

          {section name=i loop=$datos}
          <tr>
             <td>{$datos[i].Foro_titulo}</td>
          </tr>
          <tr>
            <td>Autor:{$data[i].Usuario_nombre}
                     Fecha:{$data[i].Foro_fecha} a las {$data[i].Foro_hora}</td>
             <td>{$data[i].Foro_texto}</td>
          </tr>
          {/section}

Ok, so there was the code. Now, the problem.
The $data[i].Foro_fecha variable is not displayed on the template, whereas the other variables do show as expected.
Remember that Foro_fecha is a date variable and formatted on the SQL query DATE_FORMAT(Foro_fecha, '%e').
If I do not format the date, it shows properly. What could be wrong?

Thanx in advance

ps: the SQL query with the date format instruction works as it should, on the mysql console.
ps2: I have translated some variables and functions, to get the code more readable for non-spanish users. If you find any typo, is because of the translation, not the original code.
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Jul 16, 2003 9:22 am    Post subject: Reply with quote

In your SQL select:

..., DATE_FORMAT(Foro_fecha, '%e') AS Foro_fecha, ...

otherwise the key name for the field won't be what you were expecting.
Back to top
View user's profile Send private message
c0p0n
Smarty n00b


Joined: 15 Jul 2003
Posts: 4

PostPosted: Fri Jul 18, 2003 6:26 am    Post subject: Reply with quote

thank U very much, after all it WAS db related Sad
of course, it worked ok. thanx!
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP