Skip to main content
More searchable title, added a couple more tags
Link
mickmackusa
  • 4.8k
  • 4
  • 18
  • 48

How to SET variables ina user-defined MySQL variable and increment it to produce ranking values with JDatabaseQuery?

Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
deleted 6 characters in body
Source Link
Midhat
  • 109
  • 7

I'm trying to write this query:

SET @rownumber = 0;
UPDATE #__hikers SET rank = (@rownumber:=@rownumber+1)
ORDER BY score DESC;

like JDatabaseQuery, but still got an error. Please help

UPDATE: I tried this code 1:

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->set($db->quote(@rownumber = 0));
$query->update($db->quoteName('#__hikers'));
$query->set($db->quoteName('#__rank''rank') . ' = ' .$db->quote(@rownumber:=@rownumber+1));
$query->order('score DESC');
$db->setQuery($query);
$result = $db->execute();

code 2:

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->set($db->quote(@rownumber).' = '.$db->quote (0));
$query->update($db->quoteName('#__hikers'));
$query->set($db->quoteName('#__rank''rank') .' = '.$db->quote(@rownumber).' = '. $db->quote(@rownumber).' + '. $db->quote(1));
$query->order('score DESC');
$db->setQuery($query);
$result = $db->execute();

I'm trying to write this query:

SET @rownumber = 0;
UPDATE #__hikers SET rank = (@rownumber:=@rownumber+1)
ORDER BY score DESC;

like JDatabaseQuery, but still got an error. Please help

UPDATE: I tried this code 1:

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->set($db->quote(@rownumber = 0));
$query->update($db->quoteName('#__hikers'));
$query->set($db->quoteName('#__rank') . ' = ' .$db->quote(@rownumber:=@rownumber+1));
$query->order('score DESC');
$db->setQuery($query);
$result = $db->execute();

code 2:

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->set($db->quote(@rownumber).' = '.$db->quote (0));
$query->update($db->quoteName('#__hikers'));
$query->set($db->quoteName('#__rank') .' = '.$db->quote(@rownumber).' = '. $db->quote(@rownumber).' + '. $db->quote(1));
$query->order('score DESC');
$db->setQuery($query);
$result = $db->execute();

I'm trying to write this query:

SET @rownumber = 0;
UPDATE #__hikers SET rank = (@rownumber:=@rownumber+1)
ORDER BY score DESC;

like JDatabaseQuery, but still got an error. Please help

UPDATE: I tried this code 1:

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->set($db->quote(@rownumber = 0));
$query->update($db->quoteName('#__hikers'));
$query->set($db->quoteName('rank') . ' = ' .$db->quote(@rownumber:=@rownumber+1));
$query->order('score DESC');
$db->setQuery($query);
$result = $db->execute();

code 2:

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->set($db->quote(@rownumber).' = '.$db->quote (0));
$query->update($db->quoteName('#__hikers'));
$query->set($db->quoteName('rank') .' = '.$db->quote(@rownumber).' = '. $db->quote(@rownumber).' + '. $db->quote(1));
$query->order('score DESC');
$db->setQuery($query);
$result = $db->execute();
deleted 1 character in body
Source Link
Midhat
  • 109
  • 7

I'm trying to write this querryquery:

SET @rownumber = 0;
UPDATE #__hikers SET rank = (@rownumber:=@rownumber+1)
ORDER BY score DESC;

like JDatabaseQuery, but still got an error. Please help

UPDATE: I tried this code 1:

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->set($db->quote(@rownumber = 0));
$query->update($db->quoteName('#__hikers'));
$query->set($db->quoteName('#__rank') . ' = ' .$db->quote(@rownumber:=@rownumber+1));
$query->order('score DESC');
$db->setQuery($query);
$result = $db->execute();

code 2:

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->set($db->quote(@rownumber).' = '.$db->quote (0));
$query->update($db->quoteName('#__hikers'));
$query->set($db->quoteName('#__rank') .' = '.$db->quote(@rownumber).' = '. $db->quote(@rownumber).' + '. $db->quote(1));
$query->order('score DESC');
$db->setQuery($query);
$result = $db->execute();

I'm trying to write this querry:

SET @rownumber = 0;
UPDATE #__hikers SET rank = (@rownumber:=@rownumber+1)
ORDER BY score DESC;

like JDatabaseQuery, but still got an error. Please help

UPDATE: I tried this code 1:

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->set($db->quote(@rownumber = 0));
$query->update($db->quoteName('#__hikers'));
$query->set($db->quoteName('#__rank') . ' = ' .$db->quote(@rownumber:=@rownumber+1));
$query->order('score DESC');
$db->setQuery($query);
$result = $db->execute();

code 2:

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->set($db->quote(@rownumber).' = '.$db->quote (0));
$query->update($db->quoteName('#__hikers'));
$query->set($db->quoteName('#__rank') .' = '.$db->quote(@rownumber).' = '. $db->quote(@rownumber).' + '. $db->quote(1));
$query->order('score DESC');
$db->setQuery($query);
$result = $db->execute();

I'm trying to write this query:

SET @rownumber = 0;
UPDATE #__hikers SET rank = (@rownumber:=@rownumber+1)
ORDER BY score DESC;

like JDatabaseQuery, but still got an error. Please help

UPDATE: I tried this code 1:

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->set($db->quote(@rownumber = 0));
$query->update($db->quoteName('#__hikers'));
$query->set($db->quoteName('#__rank') . ' = ' .$db->quote(@rownumber:=@rownumber+1));
$query->order('score DESC');
$db->setQuery($query);
$result = $db->execute();

code 2:

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->set($db->quote(@rownumber).' = '.$db->quote (0));
$query->update($db->quoteName('#__hikers'));
$query->set($db->quoteName('#__rank') .' = '.$db->quote(@rownumber).' = '. $db->quote(@rownumber).' + '. $db->quote(1));
$query->order('score DESC');
$db->setQuery($query);
$result = $db->execute();
added 415 characters in body
Source Link
Midhat
  • 109
  • 7
Loading
added 383 characters in body
Source Link
Midhat
  • 109
  • 7
Loading
Source Link
Midhat
  • 109
  • 7
Loading